﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Entity.DbEntity;
using Tools;
using CommandService;
//using AppCommon;
using Entity.SysEntity.Common;
using BLL.Base;
using System.Data;
using Entity.ViewEntity.sys;
using BLL.custom;
using System.Data.SqlClient;
using CommandService.Common.Base;
using Entity.ViewEntity;
using BLL.Basis;
using System.Threading;
using Entity.App;
using System.Reflection;

namespace BLL.App
{
    public class AppBLL : PubMethod
    {
        Commands cmd;
        SystemBLL sysBLL;
        ReturnResult rsl;
        //OperToken token;
        MsgResult Msg;
        OperateModel oper;
        TokenInfo TokenInfo;
        ServiceRecord ServiceRecord;
        //Common tokenCommon;
        PubMethod pubMethod;
        DataTable dt;
        TxtLogHelper txtLog;
        StringBuilder sb = new StringBuilder();
        CuDbHelper cuHelper;
        BarBLL barBLL;
        ServiceBLL serviceBLL = new ServiceBLL();
        DbProductBar barInfor;
        DbTempScanData scan;
        SqlParameter sqlParameter;
        BaseCommon baseCommon;
        AppMobilesInfo appInfo;
        AppUpdateInfo appUpdateInfo;
        PieceRateBLL priceBLL;

        public AppBLL()
        {
            cuHelper = new CuDbHelper();
            sysBLL = new SystemBLL();
            //APPcommon
            //token = new OperToken();
            //sql访问类
            cmd = new Commands();
            //sql操作类
            oper = new OperateModel();
            //token存储类
            TokenInfo = new TokenInfo();
            //移动设备调用接口记录
            ServiceRecord = new ServiceRecord();
            //设备接口记录
            //tokenCommon = new Common();
            pubMethod = new PubMethod();
            //日志记录
            txtLog = new TxtLogHelper();
            barBLL = new BarBLL();
            baseCommon = new BaseCommon();
            priceBLL = new PieceRateBLL();
        }

        /// <summary>
        /// 获取账套
        /// </summary>
        /// <returns></returns>
        public ReturnResult getAccount(string str)
        {
            #region 获取账套
            rsl = new ReturnResult();
            try
            {
                string acount = string.Empty;
                if (string.IsNullOrWhiteSpace(str))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                #region 解密方法
                var jsonStr = Encryption.DesDecrypt(str);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                #endregion
                //rsl = sysBLL.CustomBaseInfo();
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from V_CustomBaseInfo");
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count > 0)
                {
                    var data = new List<Dictionary<string, string>>();
                    if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                    {
                        foreach (DataRow item in table.Rows)
                        {
                            var obj = new Dictionary<string, string>();
                            obj["value"] = item["DbCode"].ToString();
                            obj["text"] = item["customName"].ToString();
                            data.Add(obj);
                        }
                    }
                    else
                    {
                        data = cmd.TableToDictionary(table);
                    }
                    rsl.Data = data;
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = "没有数据";
                }
                txtLog.AddLogMsg("getAccount:方法" + JsonConvert.SerializeObject(rsl));
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }

            return rsl;
            #endregion
        }
        /// <summary>
        /// 获取(验证)token方法
        /// </summary>
        /// <param name="datas">数据字符串(密文)</param>
        /// <returns></returns>
        public ReturnResult getToken(string datas)
        {
            #region 获取并验证token
            rsl = new ReturnResult();
            //string data = datas;//获取传来的参数数据
            //string tokens = "";
            //string appCode = "";
            //string TimeNow = pubMethod.getNow();//获取现在时间
            //string ServiceName = "getToken";
            //int Count = 0;
            //List<OperateModel> listOper = new List<OperateModel>();//事务操作数据库
            //try
            //{
            //    if (string.IsNullOrWhiteSpace(datas))
            //    {
            //        rsl.Data = false;
            //        rsl.Message = "传递参数不允许为空";
            //        return rsl;
            //    }
            //    #region 解密方法
            //    datas = Encryption.DesDecrypt(datas);
            //    #endregion
            //    var json = JsonConvert.DeserializeObject<JObject>(datas);//参数格式{appCode:"",token:""}
            //    #region 判断设备码是否为空
            //    if (!string.IsNullOrWhiteSpace(json["appCode"].ToString()))
            //    {
            //        #region 设备码有效判断
            //        ProgramInfo programInfo = new ProgramInfo();
            //        appCode = json["appCode"].ToString();
            //        programInfo.apCode = appCode;
            //        //根据appCode查询移动设备信息表是否存在该设备
            //        Count = cmd.GetDataByObject<ProgramInfo>(programInfo).Count;
            //        programInfo.apVersion = "";
            //        programInfo.createTime = TimeNow;
            //        //如果能查到设备码
            //        if (Count > 0)
            //        {
            //            #region 判断token记录表是否有该设备信息
            //            TokenInfo.appCode = appCode;
            //            Count = cmd.GetDataByObject<TokenInfo>(TokenInfo).Count;
            //            if (Count > 0)
            //            {
            //                #region 判断token有效性
            //                //先判断是否传过来token
            //                if (!string.IsNullOrWhiteSpace(json["token"].ToString()))
            //                {
            //                    #region 数据库中查询token是否存在
            //                    StringBuilder sb = new StringBuilder();
            //                    sb.Append("select * from ap_TokenInfo where token='" + json["token"].ToString() + "'");
            //                    sb.Append(" and appCode='" + appCode + "'");
            //                    var dt = cmd.GetDataTable(sb.ToString());
            //                    if (dt.Rows.Count > 0)
            //                    {
            //                        #region 判断是否在有效时间内
            //                        //查询token的创建时间
            //                        string dateTime = dt.Rows[0]["createtime"].ToString();
            //                        DateTime getdateTime = DateTime.Parse(dateTime);
            //                        DateTime nowDate = DateTime.Now;
            //                        TimeSpan timeSpan = nowDate - getdateTime;
            //                        int minu = timeSpan.Minutes;//相差的时间 
            //                        rsl = sysBLL.getParameterByCode("ValidToken"); //获取token有效时长
            //                        if (rsl.Result)
            //                        {
            //                            var list = (List<Dictionary<string, string>>)rsl.Data;
            //                            string validMinute = list[0]["parValue"];//系统中规定的有效时长
            //                            //时间比较，是否超出有效时长；
            //                            if (minu > Convert.ToInt32(validMinute))
            //                            {
            //                                rsl.Result = false;
            //                                rsl.Data = "";
            //                                rsl.Message = "Token超时，请重新获取";
            //                                return rsl;
            //                            }
            //                            else
            //                            {
            //                                //直接返回有效token
            //                                rsl.Data = json["token"].ToString();
            //                                rsl.Result = true;
            //                                return rsl;
            //                            }
            //                        }
            //                        else
            //                        {
            //                            rsl.Message = "系统未设置token有效时间";
            //                            rsl.Result = false;
            //                            return rsl;
            //                        }
            //                        #endregion
            //                    }
            //                    else
            //                    {
            //                        //重新生成token 并更新数据库
            //                        oper = updateToken(appCode, TimeNow, ref tokens);
            //                        listOper.Add(oper);
            //                    }
            //                    #endregion
            //                }
            //                else
            //                {
            //                    //重新生成token 并更新数据库
            //                    oper = updateToken(appCode, TimeNow, ref tokens);
            //                    listOper.Add(oper);
            //                }
            //                #endregion
            //            }
            //            else
            //            {
            //                //直接往token表中添加设备号和token
            //                tokens = token.getToken();//获取新的token
            //                TokenInfo.token = tokens;
            //                TokenInfo.createtime = TimeNow;
            //                oper.Data = TokenInfo;
            //                oper.Types = OperateModel.OperateType.Add;
            //                listOper.Add(oper);
            //            }
            //            #endregion
            //            rsl = cmd.MoreUpdate(listOper);
            //            if (rsl.Result)
            //            {
            //                rsl.Result = true;
            //                rsl.Data = tokens;
            //                return rsl;
            //            }
            //            else
            //            {
            //                Msg.Msg = "sql执行错误,请联系开发者。";
            //                Msg.result = false;
            //                Msg.MsgCode = "03001";
            //            }
            //        }
            //        else//不能查到设备码，就添加
            //        {
            //            //添加设备信息
            //            oper.Data = programInfo;
            //            oper.Types = OperateModel.OperateType.Add;
            //            listOper.Add(oper);
            //            //事务执行sql
            //            rsl = cmd.MoreUpdate(listOper);
            //            this.getToken(data);//再次获取token
            //        }
            //        #endregion
            //    }
            //    else
            //    {
            //        rsl.Result = false;
            //        rsl.Message = "设备码不能为空";
            //        return rsl;
            //    }
            //    #endregion

            //}
            //catch (Exception ex)
            //{
            //    rsl.Result = false;
            //    rsl.Message = ex.Message;
            //    return rsl;
            //}
            return rsl;
            #endregion
        }


        /// <summary>
        /// 根据appCode更新token
        /// </summary>
        /// <param name="appCode"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private OperateModel updateToken(string appCode, string timeNow, ref string tokens)
        {
            //重新生成token 并更新数据库
            TokenInfo = new TokenInfo();
            //TokenInfo.appCode = appCode;
            //tokens = token.getToken();//生成一个新的token
            TokenInfo.token = tokens;
            //TokenInfo.createtime = timeNow;
            oper.Data = TokenInfo;
            oper.Types = OperateModel.OperateType.Edit;
            oper.Conditions = "appCode";
            return oper;
        }

        /// <summary>
        /// 登录验证
        /// </summary>
        /// <returns></returns>
        public ReturnResult login(String jsonStr)
        {
            #region 登录验证
            try
            {
                rsl = new ReturnResult();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数丢失";
                    return rsl;
                }
                //rsl = getToken(jsonStr);
                //if (!rsl.Result)
                //{
                //    return rsl;
                //}
                #region 解密方法
                jsonStr = Encryption.DesDecrypt(jsonStr);

                #endregion
                txtLog.AddLogMsg("login方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                if (string.IsNullOrWhiteSpace(json["userCode"].ToString()))
                {
                    rsl.Result = false;
                    rsl.Message = "登录账号不允许为空";
                    return rsl;
                }
                if (string.IsNullOrWhiteSpace(json["userPwd"].ToString()))
                {
                    rsl.Result = false;
                    rsl.Message = "登录密码不允许为空";
                    return rsl;
                }

                DbUser user = new DbUser();
                user.userCode = json["userCode"].ToString().Trim();
                user.userPwd = Tools.Encryption.DesEncrypt(json["userPwd"].ToString().Trim());
                user.status = "Y";//启用状态
                var list = cmd.GetDataByObject<LoginUser>(user);
                if (list.Count > 0)
                {
                    list[0].baseCode = json["baseCode"].ToString();
                    rsl.Data = list[0];
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = "账号或密码错误";
                }
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
            #endregion
        }

        /// <summary>
        /// 获取仓库信息
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getWareHouse(string jsonStr)
        {
            try
            {
                rsl = new ReturnResult();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                #region 解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                #endregion
                txtLog.AddLogMsg("getWareHouse方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                var inOutTypeFalse = new[] { "pibg", "pobg", "piyb", "poyb" };
                StringBuilder sb = new StringBuilder();
                if (json.Property("inOutType") != null && !string.IsNullOrWhiteSpace(json["inOutType"].ToString()))
                {
                    if (json["inOutType"].ToString().Equals("pobg") || json["inOutType"].ToString().Equals("pibg"))
                    {
                        sb.Clear();
                        sb.Append("select * from fun_CommonData_Info where");
                        sb.Append(" isdel=0 and ctype='ysfs' and status='Y'");
                    }
                    else if (!inOutTypeFalse.Contains(json["inOutType"].ToString()))
                    {
                        sb.Clear();
                        sb.Append("select houseCode code,houseName name from fun_WareHouse_Info");
                        sb.Append(" where isdel=0 and status='open'");
                        if (!string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                        {
                            sb.Append(" and baseCode = '" + json["baseCode"] + "'");
                        }
                    }

                    var table = cmd.GetDataTable(sb.ToString());
                    var data = new List<Dictionary<string, string>>();
                    if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                    {
                        if (table.Rows.Count > 0)
                        {
                            foreach (DataRow item in table.Rows)
                            {
                                var obj = new Dictionary<string, string>();
                                obj["value"] = item["code"].ToString();
                                obj["text"] = item["name"].ToString() + "(" + item["code"].ToString() + ")";
                                data.Add(obj);
                            }
                        }
                    }
                    else
                    {
                        data = cmd.TableToDictionary(table);
                    }
                    rsl.Data = data;
                    rsl.Result = true;

                }

                //var table = cmd.GetDataTable(sb.ToString());
                //var data = new List<Dictionary<string, string>>();
                //if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                //{
                //    if (table.Rows.Count > 0)
                //    {
                //        foreach (DataRow item in table.Rows)
                //        {
                //            var obj = new Dictionary<string, string>();
                //            obj["value"] = item["code"].ToString();
                //            obj["text"] = item["name"].ToString() + "(" + item["code"].ToString() + ")";
                //            data.Add(obj);
                //        }
                //    }
                //}
                //else
                //{
                //    data = cmd.TableToDictionary(table);
                //}
                //rsl.Data = data;
                //rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = "发生仓库：" + ex.Message;
                return rsl;
            }
            return rsl;
        }
       
        /// <summary>
        /// 获取部门信息
        /// </summary>
        /// <param name="josnStr"></param>
        /// <returns></returns>
        public ReturnResult getDepartment(string jsonStr)
        {
            try
            {
                rsl = new ReturnResult();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //rsl = this.getToken(jsonStr);
                //    if(!rsl.Result){
                //        return rsl;
                //    }
                #region 解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                #endregion
                txtLog.AddLogMsg("getDepartment方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb = new StringBuilder();
                sb.Append("select depCode code,depName name from sys_DepartMent_Info where status='Y'");
                if (!string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                {
                    sb.Append(" and baseCode = '" + json["baseCode"] + "'");
                }
                var table = cmd.GetDataTable(sb.ToString());
                var data = new List<Dictionary<string, string>>();
                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    if (table.Rows.Count > 0)
                    {
                        foreach (DataRow item in table.Rows)
                        {
                            var obj = new Dictionary<string, string>();
                            obj["value"] = item["code"].ToString();
                            obj["text"] = item["name"].ToString();
                            data.Add(obj);
                        }
                    }
                }
                else
                {
                    data = cmd.TableToDictionary(table);
                }
                rsl.Data = data;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = "发生部门：" + ex.Message;
                return rsl;
            }
            return rsl;
        }
        /// <summary>
        /// 获取存货信息
        /// </summary>
        /// <param name="josnStr"></param>
        /// <returns></returns>
        public ReturnResult getInventory(string jsonStr)
        {
            try
            {
                rsl = new ReturnResult();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                var listDic = new Dictionary<string, object>();
                //rsl = this.getToken(jsonStr);
                //    if(!rsl.Result){
                //        return rsl;
                //    }
                #region 解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                #endregion
                txtLog.AddLogMsg("getInventory方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb = new StringBuilder();

                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    #region H5移动端方法
                    sb.Clear();
                    sb.Append("select inv.*,invc.cName typeCodeName,cunit.cName mUnitName  from fun_Inventory_Info inv ");
                    sb.Append(" left join fun_InvenClass_Info invc on inv.typeCode=invc.cCode ");
                    sb.Append(" left join fun_CommonData_Info cunit on inv.mUnit=cunit.cCode and cType='cUnit' ");
                    sb.Append(" where inv.status='Y' and inv.isDel='0' and invc.status='open' and invc.isDel='0' ");
                    if (json.Property("baseCode") != null && !string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                    {
                        sb.Append(" and inv.baseCode = '" + json["baseCode"] + "'");
                        sb.Append(" and invc.baseCode = '" + json["baseCode"] + "'");
                    }
                    if (json.Property("proCode") != null && !string.IsNullOrWhiteSpace(json["proCode"].ToString()))
                    {
                        sb.Append(" and proCode  like '%" + json["proCode"].ToString() + "%' ");
                    }
                    if (json.Property("proName") != null && !string.IsNullOrWhiteSpace(json["proName"].ToString()))
                    {
                        sb.Append(" and proName like '%" + json["proName"].ToString() + "%' ");
                    }
                    if (json.Property("typeCode") != null && !string.IsNullOrWhiteSpace(json["typeCode"].ToString()))
                    {
                        sb.Append(" and typeCode ='" + json["typeCode"].ToString() + "' ");
                    }
                    #endregion
                    var assistant = cmd.GetDataTable(sb.ToString());
                    var assistantList = cmd.TableToDictionary(assistant);
                    var headData = new List<Object>();
                    var obj = new { field = "proCode", name = "存货编码", width = "100" };
                    headData.Add(obj);
                    obj = new { field = "proName", name = "存货名称", width = "100" };
                    headData.Add(obj);
                    obj = new { field = "spec", name = "存货类型", width = "100" };
                    headData.Add(obj);
                    obj = new { field = "typeCodeName", name = "大类名称", width = "100" };
                    headData.Add(obj);
                    obj = new { field = "mUnitName", name = "主计量单位", width = "100" };
                    headData.Add(obj);
                    listDic.Add("headData", headData);
                    listDic.Add("list", assistantList);
                    rsl.Data = listDic;
                    rsl.Result = true;
                }
                else
                {
                    sb.Clear();
                    sb.Append("select proCode as code,proName  as name ,spec as style from fun_Inventory_Info where status='open' and isDel='0'");
                    if (!string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                    {
                        sb.Append(" and baseCode = '" + json["baseCode"] + "'");
                    }

                    if (!string.IsNullOrWhiteSpace(json["conditions"].ToString()))
                    {
                        sb.Append(" and ( proCode like '%" + json["conditions"].ToString() + "%'");
                        sb.Append(" or proName like '%" + json["conditions"].ToString() + "%'");
                        sb.Append(" or spec like '%" + json["conditions"].ToString() + "%')");
                    }
                    var list = cmd.TableToDictionary(cmd.GetDataTable(sb.ToString()));
                    Dictionary<String, String> dic = new Dictionary<string, string>();
                    dic.Add("code", "存货编码");
                    dic.Add("name", "存货名称");
                    dic.Add("style", "存货类型");
                    list.Insert(0, dic);
                    rsl.Data = list;
                    rsl.Result = true;
                }
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }
   
        /// <summary>
        ///获取收发类型与出入库的对应关系
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>getInOutWareStyle
        public ReturnResult getInOutRdStyle(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取收发类型
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对穿入数据进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                StringBuilder sb = new StringBuilder();
                sb.Append("select parCode AS code, parName AS name,parValue as value from sys_parameters_info");
                sb.Append(" where isDel=0 and enable='open'  and parCode like '%Rd_Style'");
                var rdStyle = cmd.GetDataTable(sb.ToString());
                rsl.Data = cmd.TableToDictionary(rdStyle);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }
        /// <summary>
        ///获取部门类型与出入库的对应关系
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public ReturnResult getInOutDeptStyle(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取收发类型
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对穿入数据进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                StringBuilder sb = new StringBuilder();
                sb.Append("select parCode AS code, parName AS name,parValue as value from sys_parameters_info");
                sb.Append(" where isDel=0 and enable='open'  and parCode like '%Dept_Style'");
                var wareStyle = cmd.GetDataTable(sb.ToString());
                rsl.Data = cmd.TableToDictionary(wareStyle);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }
        /// <summary>
        ///获取部门类型与出入库的对应关系
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public ReturnResult getInOutWareStyle(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取收发类型
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对穿入数据进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                StringBuilder sb = new StringBuilder();
                sb.Append("select parCode AS code, parName AS name,parValue as value from sys_parameters_info");
                sb.Append(" where isDel=0 and enable='open'  and parCode like '%Ware_Style'");
                var wareStyle = cmd.GetDataTable(sb.ToString());
                rsl.Data = cmd.TableToDictionary(wareStyle);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        public ReturnResult getUserInfo(string jsonStr)
        {
            rsl = new ReturnResult();
            Dictionary<string, string> dic = new Dictionary<string, string>();
            Dictionary<string, object> listDic = new Dictionary<string, object>();
            List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
            #region 获取人员信息
            try
            {
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //字符串解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                txtLog.AddLogMsg("getAssistantInfo方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);

                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    #region H5移动端方法
                    sb.Clear();
                    sb.Append("select id,userCode,userName from sys_users_info  ");
                    sb.Append(" where 1=1 and status='Y' and isDel<>1 ");
                    if (json.Property("baseCode") != null && !string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                    {
                        sb.Append(" and baseCode ='" + json["baseCode"].ToString() + "' ");
                    }
                    if (json.Property("userCode") != null && !string.IsNullOrWhiteSpace(json["userCode"].ToString()))
                    {
                        sb.Append(" and userCode  like '%" + json["userCode"].ToString() + "%' ");
                    }
                    if (json.Property("userName") != null && !string.IsNullOrWhiteSpace(json["userName"].ToString()))
                    {
                        sb.Append(" and userName like '%" + json["userName"].ToString() + "%' ");
                    }
                    ///默认加载人员数据（若查询类型下根据编码或名称查询时将查询所有数据）
                    if (json.Property("defalutUser") != null && !string.IsNullOrWhiteSpace(json["defalutUser"].ToString()) && json.Property("type") != null && !json["type"].ToString().Equals("query"))
                    {
                        var userCode = "";
                        var userList = JsonConvert.DeserializeObject<List<string>>(json["defalutUser"].ToString());
                        if (userList != null && userList.Count > 0)
                        {
                            foreach (var item in userList)
                            {
                                userCode += "'" + item + "'" + ",";
                            }
                        }
                        userCode = userCode.TrimEnd(',');
                        sb.Append(" and userCode in(" + userCode + ") ");
                    }
                    #endregion
                    var assistant = cmd.GetDataTable(sb.ToString());
                    var assistantList = cmd.TableToDictionary(assistant);
                    var headData = new List<Object>();
                    var obj = new { field = "userCode", name = "用户账号", width = "100" };
                    headData.Add(obj);
                    obj = new { field = "userName", name = "用户名称", width = "100" };
                    headData.Add(obj);
                    listDic.Add("headData", headData);
                    listDic.Add("list", assistantList);
                }
                rsl.Data = listDic;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        /// <summary>
        /// 获取公共数据信息
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getCommonDataInfo(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取公共数据信息
            try
            {
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                var listDic = new Dictionary<string, object>();
                //字符串解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                txtLog.AddLogMsg("getCommonDataInfo：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Append("select * from fun_CommonData_Info where 1=1 ");
                sb.Append(" and convert(int,isDel)<>1 ");
                if (json.Property("cType") != null && !string.IsNullOrWhiteSpace(json["cType"].ToString()))
                {
                    sb.Append(" and cType='" + json["cType"].ToString() + "' ");
                }
                var table = cmd.GetDataTable(sb.ToString());
                var data = new List<Dictionary<string, string>>();
                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    if (table.Rows.Count > 0)
                    {
                        foreach (DataRow item in table.Rows)
                        {
                            var obj = new Dictionary<string, string>();
                            obj["value"] = item["cCode"].ToString();
                            obj["text"] = item["cName"].ToString();
                            data.Add(obj);
                        }
                    }
                }
                else
                {
                    data = cmd.TableToDictionary(table);
                }
                rsl.Data = data;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }
     
        /// <summary>
        /// 获取客户信息
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getCustomer(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取客户信息
            try
            {
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //字符串解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                txtLog.AddLogMsg("getCustomer方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Append("SELECT   c.cuCode as code, c.cuName as name,c.baseCode,sd.name AS cName ");
                sb.Append("FROM dbo.fun_Customs_info AS c INNER JOIN ");
                sb.Append(" dbo.sys_dictionaries_info AS d ON c.status = d.code AND d.types = 'ps' INNER JOIN ");
                sb.Append(" dbo.sys_dictionaries_info AS sd ON c.cuType = sd.code AND sd.types = 'cst' ");
                //sb.Append("select c.cCusCode code,c.cCusName name,cc.cCCCode,cc.cCCName cName from Customer c  ");
                //sb.Append("LEFT JOIN CustomerClass cc on c.cCCCode=cc.cCCCode ");
                if (!string.IsNullOrWhiteSpace(json["conditions"].ToString()))
                {
                    sb.Append("where c.cuName like '%" + json["conditions"].ToString() + "%' ");
                }
                if (!string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                {
                    sb.Append(" and c.baseCode like '%" + json["baseCode"].ToString() + "%' ");
                }
                var customers = cmd.GetDataTable(sb.ToString());
                //sb.Append("order by cc.cCCCode ASC");
                //var customers = cuHelper.getData(sb.ToString(), json["baseCode"].ToString());//U8用户信息
                rsl.Data = cmd.TableToDictionary(customers);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }
        /// <summary>
        /// 获取T+销货单列表
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getSaleOrderList(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取T+销货单信息
            try
            {
                List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
                Dictionary<string, object> dic = new Dictionary<string, object>();
                List<int> widthList = new List<int>();//列宽度列表
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                
                //字符串解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                txtLog.AddLogMsg("getSaleOrderList方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);

                #region  销货单数据 （top100）
                sb.Append("select top 100 s.id,convert(date,voucherdate) dDate ,s.code cDLCode,p.code cCusCode,p.name cCusName ");
                sb.Append("from SA_SaleDelivery s inner join AA_PartnerEntity p on p.id = s.idcustomer where  auditeddate is null ");
                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    if (json.Property("orderCode") != null && !string.IsNullOrWhiteSpace(json["orderCode"].ToString()))
                    {
                        sb.Append(" and s.code like '%" + json["orderCode"].ToString().Trim() + "%' ");
                    }
                    if (json.Property("cuName") != null && !string.IsNullOrWhiteSpace(json["cuName"].ToString()))
                    {
                        sb.Append(" and p.name like '%" + json["cuName"].ToString().Trim() + "%' ");
                    }
                    if (json.Property("date") != null && !string.IsNullOrWhiteSpace(json["date"].ToString()))
                    {
                        sb.Append(" and convert(date,voucherdate) = '" + json["date"].ToString().Trim() + "' ");
                    }
                }
                sb.Append(" order by voucherdate desc,s.code desc ");
                var table = new DataTable();
                if (!string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                {
                    table = cuHelper.getData(sb.ToString(), json["baseCode"].ToString());
                }
                if (table.Rows.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有数据";
                    return rsl;
                }

                #endregion
                var saleList = cmd.TableToDictionary(table);

                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    #region 构建表头数据
                    var headData = new List<object>();
                    var head = new Dictionary<string, string>();
                    var obj = new { field = "cDLCode", name = "销货单", width = "150" };
                    headData.Add(obj);
                    obj = new { field = "cCusName", name = "客户名称", width = "150" };
                    headData.Add(obj);
                    obj = new { field = "dDate", name = "单据日期", width = "80" };
                    headData.Add(obj);
                    #endregion
                    dic.Add("headData", headData);
                    dic.Add("list", saleList);
                }

                rsl.Data = dic;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }
        /// <summary>
        /// 获取借出归回单列表
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getBorrowOutBackList(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取借出归回单列表
            try
            {
                List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
                Dictionary<string, object> dic = new Dictionary<string, object>();
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //字符串解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                txtLog.AddLogMsg("getBorrowOutBackList方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                //sb.Append(" select cCODE as cCode,ddate from HY_DZ_BorrowOutBack ");
                //sb.Append("  where isnull(cHandler,'') <>'' and isnull(dVeriDate,'') <>''  ");
                sb.Append(getU8BorrowOutBack());
                if (!string.IsNullOrWhiteSpace(json["conditions"].ToString()))
                {
                    sb.Append(" and (br.cCODE like '%" + json["conditions"] + "%' ");//计划单号
                    sb.Append(" or brs.cinvcode like '%" + json["conditions"].ToString() + "%'");//存货编码
                    sb.Append(" or v.cInvName like '%" + json["conditions"].ToString() + "%')");//存货名称  
                }
                sb.Append(" order by br.ddate desc,br.cCODE desc ");
                var table = new DataTable();
                if (!string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                {
                    table = cuHelper.getData(sb.ToString(), json["baseCode"].ToString());
                }
                //sb.Append("order by cc.cCCCode ASC");
                //var customers = cuHelper.getData(sb.ToString(), json["baseCode"].ToString());//U8用户信息
                if (table.Rows.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有数据";
                    return rsl;
                }
                var saleList = cmd.TableToDictionary(table);
                Dictionary<string, string> temdic = new Dictionary<string, string>();
                temdic.Add("cCode", "借出归还单");
                //temdic.Add("cCusCode", "客户编码");
                //temdic.Add("cCusName", "客户名称");
                temdic.Add("proCode", "存货编码");
                temdic.Add("proName", "存货名称");
                temdic.Add("spec", "存货型号");
                temdic.Add("ddate", "归还日期");
                saleList.Insert(0, temdic);
                dic.Add("list", saleList);
                rsl.Data = dic;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }
        /// <summary>
        /// 获取借出借用单列表
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getBorrowOutList(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取借出借用单列表
            try
            {
                List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
                Dictionary<string, object> dic = new Dictionary<string, object>();
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //字符串解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                txtLog.AddLogMsg("getBorrowOutList方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Append(AppBLL.getU8BorrowOut());
                if (!string.IsNullOrWhiteSpace(json["conditions"].ToString()))
                {
                    sb.Append(" and (br.cCODE like '%" + json["conditions"] + "%' ");//计划单号
                    sb.Append(" or cus.cCusCode like '%" + json["conditions"].ToString() + "%'");//客户编码
                    sb.Append(" or brs.cinvcode like '%" + json["conditions"].ToString() + "%'");//存货编码
                    sb.Append(" or v.cInvName like '%" + json["conditions"].ToString() + "%')");//存货名称              
                }
                sb.Append(" order by br.ddate desc,br.cCODE desc ");
                var table = new DataTable();
                if (!string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                {
                    table = cuHelper.getData(sb.ToString(), json["baseCode"].ToString());
                }
                if (table.Rows.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有数据";
                    return rsl;
                }
                var saleList = cmd.TableToDictionary(table);
                Dictionary<string, string> temdic = new Dictionary<string, string>();
                temdic.Add("cCode", "借出借用单");
                temdic.Add("cCusCode", "客户编码");
                temdic.Add("cCusName", "客户名称");
                temdic.Add("proCode", "存货编码");
                temdic.Add("proName", "存货名称");
                temdic.Add("spec", "存货型号");
                temdic.Add("ddate", "借出日期 ");
                saleList.Insert(0, temdic);
                dic.Add("list", saleList);
                rsl.Data = dic;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }
        /// <summary>
        /// 获取发货退货单列表
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getDispatchList(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取发货退货单列表
            try
            {
                List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
                Dictionary<string, object> dic = new Dictionary<string, object>();
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //字符串解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                txtLog.AddLogMsg("getDispatchList方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Append(" select * from DispatchList d ");
                sb.Append("");
                sb.Append("");
                sb.Append("");
                sb.Append(" inner join DispatchLists ds on d.DLID = ds.DLID ");
                sb.Append(" where d.cSOCode='" + json["cSoCode"].ToString() + "' ");
                var table = new DataTable();
                if (!string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                {
                    table = cuHelper.getData(sb.ToString(), json["baseCode"].ToString());
                }
                //sb.Append("order by cc.cCCCode ASC");
                //var customers = cuHelper.getData(sb.ToString(), json["baseCode"].ToString());//U8用户信息
                if (table.Rows.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有数据";
                    return rsl;
                }
                var saleList = cmd.TableToDictionary(table);
                Dictionary<string, string> temdic = new Dictionary<string, string>();
                temdic.Add("cSOCode", "销售订单");
                temdic.Add("cCusCode", "客户编码");
                temdic.Add("cCusName", "客户名称");
                temdic.Add("dDate", "创建时间");
                saleList.Insert(0, temdic);
                dic.Add("list", saleList);
                list.Add(dic);
                rsl.Data = list;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }
        /// <summary>
        /// 获取生产计划单列表（U8）
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getProductPlan(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取U8生产计划单信息
            try
            {
                List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
                Dictionary<string, object> dic = new Dictionary<string, object>();
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //字符串解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                txtLog.AddLogMsg("getProductPlan方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Append(AppBLL.U8ProductPlanQueryString());//U8生产订单
                if (!string.IsNullOrWhiteSpace(json["conditions"].ToString()))
                {
                    sb.Append(" and (m.MoCode like '%" + json["conditions"] + "%' ");//计划单号
                    sb.Append(" or o.InvCode like '% " + json["conditions"].ToString() + "%'");//存货编码
                    sb.Append(" or v.cInvName like '%" + json["conditions"].ToString() + "%')");//存货名称
                }
                sb.Append(" order by m.createtime desc,o.moid desc");
                var table = new DataTable();
                if (!string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                {
                    table = cuHelper.getData(sb.ToString(), json["baseCode"].ToString());
                }
                table.Columns["orderNO"].SetOrdinal(1);
                table.Columns["hanghao"].SetOrdinal(2);
                table.Columns["proCode"].SetOrdinal(3);
                table.Columns["proName"].SetOrdinal(4);
                table.Columns["spec"].SetOrdinal(5);
                table.Columns["createtime"].SetOrdinal(6);
                var dicColum = new Dictionary<int, string>();
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    var item = table.Columns[i].ToString();
                    dicColum.Add(i, item);
                }
                //移除不需要的字段
                foreach (var item in dicColum.Values)
                {
                    if (!item.Equals("orderNO") && !item.Equals("proCode") && !item.Equals("proName") && !item.Equals("createtime") && !item.Equals("hanghao") && !item.Equals("spec"))
                    {
                        table.Columns.Remove(item.ToString());
                    }
                }
                if (table.Rows.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有数据";
                    return rsl;
                }
                var planList = cmd.TableToDictionary(table);
                Dictionary<string, string> temdic = new Dictionary<string, string>();
                temdic.Add("orderNO", "生产单号");
                temdic.Add("hanghao", "行号");
                temdic.Add("proCode", "存货编码");
                temdic.Add("proName", "存货名称");
                temdic.Add("spec", "存货型号");
                temdic.Add("createtime", "创建时间");
                planList.Insert(0, temdic);
                dic.Add("list", planList);
                list.Add(dic);
                rsl.Data = list;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }
    

        /// <summary>
        /// 获取调拨申请单列表（U8）
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getAllotRecordsInfo(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取U8调拨申请单列表
            try
            {
                List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
                Dictionary<string, object> dic = new Dictionary<string, object>();
                List<int> widthList = new List<int>();
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //字符串解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                txtLog.AddLogMsg("getAllotRecordsInfo方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                //sb.Append(AppBLL.U8allotRecordsQueryString());//U8调拨申请单列表
                sb.Append("select top 100 tv.cTVCode  orderNO,");//填写U8计划信息
                sb.Append("tv.dTVDate createtime ,tv.cOWhCode outWareHouseCode,ow.cWhName outWareHouseName,");
                sb.Append("tv.cIWhCode inWareHouseCode,iw.cWhName inWareHouseName ");
                sb.Append(" from ST_AppTransVouch tv ");
                sb.Append(" inner join Warehouse  ow on ow.cWhCode=tv.cOWhCode");
                sb.Append(" inner join Warehouse  iw on iw.cWhCode=tv.cIWhCode");
                sb.Append(" where tv.dVerifyDate is not null and tv.cCloser is null");
                if (!string.IsNullOrWhiteSpace(json["conditions"].ToString()))
                {
                    sb.Append(" and (tv.cTVCode like '%" + json["conditions"] + "%' ");//计划单号
                    sb.Append(" or tv.cIWhCode like '%" + json["conditions"].ToString() + "%'");//存货名称
                    sb.Append(" or tv.cOWhCode like '%" + json["conditions"].ToString() + "%'");//存货名称
                    sb.Append(" or ow.cWhName like '%" + json["conditions"].ToString() + "%'");//存货名称
                    sb.Append(" or iw.cWhName like '%" + json["conditions"].ToString() + "%')");//存货名称
                }
                sb.Append(" order by tv.dTVDate  desc");
                var table = new DataTable();
                if (!string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                {
                    table = cuHelper.getData(sb.ToString(), json["baseCode"].ToString());
                }
                if (table.Rows.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有数据";
                    return rsl;
                }
                var planList = cmd.TableToDictionary(table);
                Dictionary<string, string> temdic = new Dictionary<string, string>();
                var widths = new int[] { 150, 120, 150, 150, 150, 180 };
                widthList = widths.ToList();
                temdic.Add("orderNO", "调拨申请单号");
                temdic.Add("outWareHouseCode", "调出仓库编码");
                temdic.Add("outWareHouseName", "调出仓库名称");
                temdic.Add("inWareHouseCode", "调入仓库编码");
                temdic.Add("inWareHouseName", "调入仓库名称");
                temdic.Add("createtime", "创建时间");
                planList.Insert(0, temdic);
                dic.Add("widthList", widthList);
                dic.Add("list", planList);
                rsl.Data = dic;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        /// <summary>
        /// 扫描编码生成方法
        /// </summary>   
        /// <returns></returns>
        public ReturnResult getScanCode(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取扫描单号
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对字符串进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                txtLog.AddLogMsg("getScanCode方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                if (string.IsNullOrWhiteSpace(json["types"].ToString()) || string.IsNullOrWhiteSpace(json["memo"].ToString()))
                {
                    rsl.Result = false;
                    rsl.Message = "条码类别参数值不能为空";
                    return rsl;
                }
                rsl.Data = barBLL.CreateBarCode(json["types"].ToString(), json["memo"].ToString());//获取扫描单号
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

      
        /// <summary>
        /// 获取U8的发货单
        /// </summary>
        /// <returns></returns>
        public static string getU8DispatchList(string orderCode, string proCode)
        {
            StringBuilder sb = new StringBuilder();
            #region 获取U8的发货单
            sb.Append(" select dis.cDLCode,dis.cDepCode,dep.cDepName,cus.cCusCode,cus.cCusName,dis.cPersonCode as personCode,");
            sb.Append(" per.cPersonName as personName,dis.dDate from DispatchList dis ");
            sb.Append(" inner join  Customer cus on cus.cCusCode=dis.cCusCode ");
            sb.Append(" inner join DispatchLists diss on dis.");
            sb.Append(" left join  Person per on dis.cPersonCode = per.cPersonCode ");
            sb.Append(" inner join Department dep on dis.cDepCode=dep.cDepCode ");
            sb.Append("  where isnull(dis.cVerifier,'') ='' and isnull(dis.dverifydate,'') =''  ");
            #endregion
            return sb.ToString();
        }
        /// <summary>
        /// 获取借出借用单
        /// </summary>
        /// <returns></returns>
        public static string getU8BorrowOut()
        {
            StringBuilder sb = new StringBuilder();
            #region 获取借出借用单
            sb.Append(" select br.cCODE as cCode,cus.cCusCode,cus.cCusName,brs.cinvcode proCode,v.cInvName proName,  ");
            sb.Append("v.cinvstd spec,br.ddate  from HY_DZ_BorrowOut br");
            sb.Append(" inner join HY_DZ_BorrowOuts brs on br.ID= brs.ID ");
            sb.Append(" inner join Inventory v on v.cInvCode=brs.cinvcode ");
            sb.Append(" left join  Customer cus on cus.cCusName=br.cdefine1 ");
            sb.Append("  where isnull(br.cHandler,'') <>'' and isnull(br.dVeriDate ,'') <>''  ");
            #endregion
            return sb.ToString();
        }
        /// <summary>
        /// 获取借出归还单
        /// </summary>
        /// <returns></returns>
        public static string getU8BorrowOutBack()
        {
            StringBuilder sb = new StringBuilder();
            #region 获取借出归回单
            sb.Append(" select br.cCODE as cCode,brs.cinvcode proCode,v.cInvName proName,  ");
            sb.Append("v.cinvstd spec,br.ddate  from HY_DZ_BorrowOutBack br");
            sb.Append(" inner join HY_DZ_BorrowOutBacks brs on br.ID= brs.ID ");
            sb.Append(" inner join Inventory v on v.cInvCode=brs.cinvcode ");
            sb.Append("  where isnull(br.cHandler,'') <>'' and isnull(br.dVeriDate ,'') <>''  ");
            #endregion
            return sb.ToString();
        }
        /// <summary>
        /// 获取U8的生产计划单sql语句
        /// </summary>
        /// <returns></returns>
        public static string U8ProductPlanQueryString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select top 100 o.InvCode proCode ,m.MoCode orderNO,v.cInvName proName,");//填写U8计划信息
            sb.Append("cinvstd spec,v.cInvCCode typeCode,m.createtime,v.bInvBatch isBatch,");
            sb.Append("'' supCode,'' supName,'' supBatchCode,convert(decimal(18,2),Qty) number,o.SortSeq hanghao ");
            sb.Append(" from mom_orderdetail o inner join Inventory v on v.cInvCode=o.InvCode");
            sb.Append(" inner join mom_order m on o.moid=m.moid");
            sb.Append(" where o.RelsDate is not null and  convert(decimal(18,2),Qty)>0 ");
            return sb.ToString();
        }
        /// <summary>
        /// 获取U8的调拨申请单sql语句
        /// </summary>
        /// <returns></returns>
        public static string U8allotRecordsQueryString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select top 100 tvs.cInvCode proCode ,tv.cTVCode  orderNO,v.cInvName proName,");//填写U8计划信息
            sb.Append("cinvstd spec,v.cInvCCode typeCode,tv.dTVDate createtime ,tv.cOWhCode outWareHouseCode,ow.cWhName outWareHouseName,");
            sb.Append("tv.cIWhCode inWareHouseCode,iw.cWhName inWareHouseName,");
            sb.Append(" convert(decimal(18,2),iTVNum) number,convert(decimal(18,2),iTVQuantity)  quantity ");
            sb.Append(" from ST_AppTransVouch tv ");
            sb.Append(" inner join ST_AppTransVouchs tvs on tv.ID = tvs.ID ");
            sb.Append(" inner join Inventory v on v.cInvCode=tvs.cInvCode");
            sb.Append(" inner join Warehouse  ow on ow.cWhCode=tv.cOWhCode");
            sb.Append(" inner join Warehouse  iw on iw.cWhCode=tv.cIWhCode");
            sb.Append(" where tv.dVerifyDate is not null and tv.cCloser is null");
            return sb.ToString();
        }
        /// <summary>
        /// 绑定条码的生产计划单
        /// </summary>
        /// <returns></returns>
        public ReturnResult saveBarCodePlan(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 绑定条码的生产计划单
            try
            {
                List<OperateModel> operList = new List<OperateModel>();
                //对字符串进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                DbProductOccupy po = new DbProductOccupy();
                if (!string.IsNullOrWhiteSpace(json["planCode"].ToString()))
                {
                    po.plCode = json["planCode"].ToString();
                    po.barCode = json["barcode"].ToString();
                    po.createtime = getNow();
                    po.createuser = json["createuser"].ToString();
                    po.ceng = "-";
                    po.memo = "mplan";
                    po.isdel = 0;
                    oper = new OperateModel();
                    oper.Data = po;
                    oper.Types = OperateModel.OperateType.Add;
                    operList.Add(oper);
                    rsl = cmd.MoreUpdate(operList);
                }
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }
        /// <summary>
        /// 保存出入库扫描的条码数据到临时表
        /// </summary>
        /// <param name="jsonStr"></param>
        public ReturnResult addScanRecord(string jsonStr)
        {
            rsl = new ReturnResult();
            DataTable planList = new DataTable();
            List<OperateModel> operList = new List<OperateModel>();
            #region 保存扫描单号数据
            try
            {
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对字符串进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var obj = JsonConvert.DeserializeObject<JObject>(jsonStr);
                if (obj.Property("barcodeNumber") != null && !string.IsNullOrWhiteSpace(obj["barcodeNumber"].ToString()))
                {
                    var tempBarCode = obj["barCode"].ToString();
                    var barCode = string.Empty;//条码编码
                    var number = string.Empty;//重量
                    for (int i = 0; i < Convert.ToInt32(obj["barcodeNumber"].ToString()); i++)
                    {
                        var str = "";
                        barCode = tempBarCode;
                        Dictionary<string, string> dic = new Dictionary<string, string>();
                        dic.Add("inOutType", obj["inOutType"].ToString());
                        dic.Add("baseCode", obj["baseCode"].ToString());
                        //判断是否为正确条码
                        rsl = serviceBLL.CheckBarCode(barCode, dic);
                        if (rsl.Result)
                        {
                            var barDataList = rsl.Data;
                            //判断是否为已扫描条码
                            rsl = serviceBLL.CheckRepeatTempBar(jsonStr);
                            if (Convert.ToInt32(rsl.Data) == 1 && rsl.Result)
                            {
                                rsl.Message = "条码已扫描";
                                rsl.Result = false;
                                return rsl;
                            }
                            rsl.Result = false;

                            List<Dictionary<string, string>> list = (List<Dictionary<string, string>>)barDataList;
                            foreach (Dictionary<string, string> item in list)
                            {
                                number = item["number"].ToString();
                                if (item["barStatus"].ToString().Equals("bar-drop"))
                                {
                                    rsl.Result = false;
                                    rsl.Message = "该SN码已作废";
                                    return rsl;
                                }
                                sb.Clear();
                                sb.Append("select sc.*,dic.name inOutTypeName from bar_TempScanData_info sc ");
                                sb.Append(" inner join sys_dictionaries_info dic on sc.inOutType=dic.code ");
                                sb.Append(" where 1=1 and tempCode<>'" + obj["tempCode"].ToString() + "' ");
                                sb.Append(" and barCode='" + barCode + "'");
                                var scDt = cmd.GetDataTable(sb.ToString());
                                if (scDt != null && scDt.Rows.Count > 0)
                                {
                                    rsl.Result = false;
                                    rsl.Message = string.Format("该条码已被扫描，扫描单据号：{0}；扫描人：{1}；操作类型：{2}", scDt.Rows[0]["tempCode"].ToString(), scDt.Rows[0]["createuser"].ToString(), scDt.Rows[0]["inOutTypeName"].ToString());
                                    return rsl;
                                }
                                
                                #region 扫码出库
                                if (obj["operateType"].ToString().Equals("02"))
                                {
                                    #region 判断条码的状态
                                    if (!item["barStatus"].Equals("need-out"))
                                    {
                                        rsl.Message = "条码为" + getBarStatus(item["barStatus"].ToString()) + "状态,不是待出库状态";
                                        rsl.Result = false;
                                        return rsl;
                                    }
                                    #endregion

                                    #region 出库时判断是否和条码所在的仓库相同
                                    if (string.IsNullOrWhiteSpace(item["wareHouse"].ToString()))
                                    {
                                        rsl.Message = "扫描的条码没有仓库信息，请确定是否入库";
                                        rsl.Result = false;
                                        return rsl;
                                    }
                                    if (!obj["wareHouse"].ToString().Equals(item["wareHouse"].ToString()))
                                    {
                                        rsl.Message = "选择的发生仓库不存在扫描的条码信息";
                                        rsl.Result = false;
                                        return rsl;
                                    }
                                    #endregion

                                    #region 检测选择的 发货单中 存货是否和扫描的相同
                                    var orderCode = obj["outOrderCode"].ToString();
                                    //if (orderCode.IndexOf('-') > 0)
                                    //{
                                    //    orderCode = obj["outOrderCode"].ToString().Split('-')[0];
                                    //}
                                    sb.Clear();
                                    sb.Append("select m.code ,m.voucherdate dDate ,s.idinventory ,i.code proCode,");
                                    sb.Append("s.quantity,s.quantity2 from SA_SaleDelivery m "); //quantity 主计量 quantity2 辅计量   出库改quantity
                                    sb.Append("inner join SA_SaleDelivery_b s on s.idSaleDeliveryDTO = m.id ");
                                    sb.Append("inner join AA_InventoryEntity i on i.id = s.idinventory ");
                                    sb.Append("where  m.code='" + orderCode + "' ");//isnull(m.auditeddate ,'') <>''  and
                                    planList = cuHelper.getData(sb.ToString(), obj["baseCode"].ToString());
                                    if (planList.Rows.Count > 0)
                                    {
                                        var comNum = DateTime.Compare(Convert.ToDateTime(planList.Rows[0]["dDate"].ToString()), Convert.ToDateTime(obj["happenDate"].ToString()));
                                        if (comNum > 0)
                                        {
                                            rsl.Result = false;
                                            rsl.Message = string.Format("出库日期小于销货单日期，销货单：{0}，出库单：{1}", planList.Rows[0]["dDate"].ToString(), obj["happenDate"].ToString());
                                            return rsl;
                                        }
                                        if (!string.IsNullOrWhiteSpace(item["proCode"].ToString()))
                                        {
                                            var selectStr = "proCode='" + item["proCode"].ToString().Trim() + "' " ;
                                            //判断属性和存货同时相同的数据
                                            var length = planList.Select(selectStr);
                                            if (length.Length <= 0)
                                            {
                                                rsl.Result = false;
                                                rsl.Message = "该销货单中没有当前扫码出库的存货信息";
                                                return rsl;
                                            }
                                            else
                                            {
                                                //if (obj.Property("isContinue") != null && !Convert.ToBoolean(obj["isContinue"].ToString()))
                                                //{
                                                //    var selectRow = length[0];
                                                //    var iQuantity = Convert.ToDecimal(selectRow["quantity"].ToString());
                                                //    #region 获取该临时码中扫描的条码个数
                                                //    sb.Clear();
                                                //    sb.Append("select bars.proCode,isnull(sum(bars.number),0) number from bar_TempScanData_info tem ");
                                                //    sb.Append("where tempCode='" + obj["tempCode"].ToString() + "'");
                                                //    sb.Append(" group by bars.proCode");
                                                //    var scanTable = cmd.GetDataTable(sb.ToString());//获取扫描单下的所有扫描记录    
                                                //    var nowIQuantity = 0.0m; //销货单重量
                                                //    var scanIQuantity = 0.0m; //扫的重量
                                                //    if (scanTable != null && scanTable.Rows.Count > 0)
                                                //    {
                                                //        var selectscan = scanTable.Select("proCode='" + item["proCode"].ToString().Trim() + "'");
                                                //        if (selectscan != null && selectscan.Length > 0)
                                                //        {
                                                //            foreach (DataRow row in selectscan)
                                                //            {
                                                //                scanIQuantity += Convert.ToDecimal(row["number"].ToString());
                                                //            }
                                                //        }
                                                //    }
                                                //    nowIQuantity = scanIQuantity + Convert.ToDecimal(item["number"].ToString());
                                                //    #endregion
                                                //    if (iQuantity < nowIQuantity)
                                                //    {
                                                //        rsl.Result = false;
                                                //        rsl.Message = string.Format("扫描数量已超出相应发货单数量，存货编码:{0},颜色:{1},商标:{2},发货单数量:{3},扫描数量:{4};是否继续?",
                                                //            item["proCode"].ToString(), item["color"].ToString(), item["trademark"].ToString(), iQuantity, nowIQuantity);
                                                //        return rsl;
                                                //    }
                                                //}
                                            }
                                        }
                                    }
                                    #endregion
                                }
                                #endregion


                            }
                           
                        }
                        else
                        {
                            rsl.Result = false;
                            return rsl;
                        }
                        rsl = serviceBLL.AddScanTempRecord(number, jsonStr, ref operList);
                        if (!rsl.Result)
                        {
                            return rsl;
                        }
                    }
                    //往扫描临时表中添加数据
                    rsl = cmd.MoreUpdate(operList);
                    if (rsl.Result)
                    {
                        var barNumber = 0;
                        #region 获取该临时码中扫描的条码个数
                        sb.Clear();
                        sb.Append("select barCode,createuser from  bar_TempScanData_info ");
                        sb.Append("where tempCode='" + obj["tempCode"].ToString() + "'");
                        var scanTable = cmd.GetDataTable(sb.ToString());//获取扫描单下的所有扫描记录    
                        if (scanTable != null && scanTable.Rows.Count > 0)
                        {
                            barNumber = scanTable.Rows.Count;
                        }
                        var dic = new Dictionary<string, string>();
                        dic["barNumber"] = barNumber.ToString();
                        rsl.Data = dic;
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

 

        /// <summary>
        /// 检测仓库是否包含货位
        /// </summary>
        /// <param name="wareHouse"></param>
        /// <param name="baseCode"></param>
        /// <returns></returns>
        public bool isWarePosition(string wareHouse, string baseCode)
        {
            var flag = false;
            sb.Clear();
            sb.Append("select cCode from fun_CommonData_Info where 1=1 ");
            sb.Append(" and parentCode='" + wareHouse + "' and cType='WP' and isDel<>1 ");
            sb.Append(" and specFile='" + baseCode + "'");
            var wpDt = cmd.GetDataTable(sb.ToString());
            if (wpDt != null && wpDt.Rows.Count > 0)
            {
                flag = true;
            }
            return flag;
        }

     
        /// <summary>
        /// 删除临时码的临时数据
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult deleteScanRecord(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 删除临时数据
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                DbTempScanData temp = new DbTempScanData();
                List<OperateModel> operList = new List<OperateModel>();
                if (!string.IsNullOrWhiteSpace(json["tempCode"].ToString()))
                {
                    if (!string.IsNullOrWhiteSpace(json["inOutType"].ToString()))
                    {
                        temp.tempCode = json["tempCode"].ToString();
                        temp.inOutType = json["inOutType"].ToString();
                        oper = new OperateModel();
                        oper.Data = temp;
                        oper.Conditions = "tempCode,inOutType";
                        oper.Types = OperateModel.OperateType.Delete;
                        operList.Add(oper);
                        rsl = cmd.MoreUpdate(operList);
                    }
                }
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }
        /// <summary>
        /// 获取临时表中的扫描单号数据
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getTempCode(string jsonStr)
        {
            rsl = new ReturnResult();
            sb = new StringBuilder();
            #region 获取临时表中的扫描数据
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Append("select parCode AS code, parName AS name,parValue as value from sys_parameters_info");
                sb.Append(" where isDel=0 and enable='open'  ");
                if (json.Property("inOutType") != null && !string.IsNullOrWhiteSpace(json["inOutType"].ToString()))
                {
                    sb.Append(" and parCode='" + json["inOutType"].ToString() + "_Rd_Style" + "'");
                }

                var rdStyle = cmd.GetDataTable(sb.ToString());
                sb.Clear();
                sb.Append(" select tmp.*,c.cName AS customName ");
                //sb.Append("  SELECT  tmp.tempCode, tmp.wareHouse, tmp.operateType, tmp.happenDate, ");
                //sb.Append(" tmp.operateDept, tmp.createuser, tmp.typeCode, tmp.isBlue,tmp.outOrderCode,  ");
                ////sb.Append(" tmp.outOrder_proCode, ");
                //sb.Append("  tmp.deptName,tmp.customCode, c.cuName AS customName ");
                sb.Append(" FROM  dbo.bar_TempScanData_info ");
                sb.Append(" AS  tmp LEFT  JOIN ");
                sb.Append(" dbo.fun_CommonData_Info AS c ON tmp.customCode = c.cCode and c.cType='Cu' ");
                sb.Append(" and c.isDel=0 and c.status='Y' and c.specFile='" + json["baseCode"].ToString() + "'");
                sb.Append(" where 1=1 ");

                if (json.Property("operateType") != null && !string.IsNullOrWhiteSpace(json["operateType"].ToString()))
                {
                    sb.Append(" and operateType ='" + json["operateType"].ToString() + "' ");
                }
                if (json.Property("inOutType") != null && !string.IsNullOrWhiteSpace(json["inOutType"].ToString()))
                {
                    sb.Append(" and  inOutType ='" + json["inOutType"].ToString() + "' ");
                }
                var tempDt = cmd.GetDataTable(sb.ToString());
                var tempCodes = new Dictionary<string, string>();
                var dt = tempDt.Clone();
                foreach (DataRow row in tempDt.Rows)
                {
                    if (!tempCodes.Keys.Contains(row["tempCode"].ToString().Trim()))
                    {
                        var rowNum = 0;
                        var selectRow = tempDt.Select("tempCode='" + row["tempCode"].ToString().Trim() + "'");
                        if (selectRow != null && selectRow.Length > 0)
                        {
                            rowNum = selectRow.Length;
                        }
                        tempCodes.Add(row["tempCode"].ToString().Trim(), rowNum.ToString());
                        dt.Rows.Add(row.ItemArray);
                    }
                }
                var data = new List<Dictionary<string, string>>();
                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    if (dt.Rows.Count > 0)
                    {
                        dt.Columns.Add("value");
                        dt.Columns.Add("text");
                        dt.Columns.Add("barNumber");
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            var item = dt.Rows[i];
                            item["value"] = item["tempCode"].ToString();
                            item["text"] = item["tempCode"].ToString();
                            item["barNumber"] = tempCodes[item["tempCode"].ToString()].ToString();
                        }
                        data = cmd.TableToDictionary(dt);
                    }
                }
                else
                {
                    data = cmd.TableToDictionary(dt);
                }
                rsl.Data = data;
                //sb.Append("GROUP BY tmp.tempCode, tmp.wareHouse, tmp.operateType, tmp.happenDate, ");
                //sb.Append(" tmp.operateDept, tmp.createuser, tmp.typeCode, tmp.isBlue,tmp.outOrderCode,  ");
                //sb.Append(" tmp.outOrder_proCode, ");
                //sb.Append("  tmp.deptName,tmp.customCode, c.cuName");
                //var dt = cmd.GetDataTable(sb.ToString());
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            #endregion

            return rsl;
        }

      
        /// <summary>
        /// 保存调拨扫描的条码数据到临时表
        /// </summary>
        /// <param name="jsonStr"></param>
        public ReturnResult addAllotScanRecord(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 保存扫描单号数据
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对字符串进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                //判断是否为正确条码
                rsl = serviceBLL.CheckBarCode(json["barCode"].ToString(), null);
                if (rsl.Result)
                {
                    List<Dictionary<string, string>> list = (List<Dictionary<string, string>>)rsl.Data;
                    foreach (Dictionary<string, string> item in list)
                    {
                        if (item["barStatus"].Equals("NI"))
                        {
                            rsl.Message = "条码未入库";
                            rsl.Result = false;
                            return rsl;
                        }
                        if (item["barStatus"].Equals("NK"))
                        {
                            rsl.Message = "条码已出库";
                            rsl.Result = false;
                            return rsl;
                        }
                        if (!item["wareHouse"].Equals(json["wareHouse"].ToString()))
                        {
                            rsl.Message = "条码不在调出仓库中";
                            rsl.Result = false;
                            return rsl;
                        }
                    }

                    //判断是否为已扫描条码
                    rsl = serviceBLL.CheckRepeatTempBar(jsonStr);
                    if (Convert.ToInt32(rsl.Data) == 1 && rsl.Result)
                    {
                        rsl.Message = "条码已扫描";
                        rsl.Result = false;
                        return rsl;
                    }
                    else
                    {
                        //rsl = serviceBLL.AddScanTempRecord(jsonStr);
                    }
                }
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }
        /// <summary>
        /// 获取用户移动端权限信息的列表
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getUserPowerList(string jsonStr)
        {
            try
            {
                rsl = new ReturnResult();
                scan = new DbTempScanData();
                oper = new OperateModel();
                Dictionary<string, object> dic = new Dictionary<string, object>();
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                DbUser user = new DbUser();
                user.userCode = json["userCode"].ToString();
                user.status = "Y";
                user.isDel = 0;
                var userLsit = cmd.GetDataByObject<DbUser>(user);
                if (userLsit.Count > 0)
                {
                    foreach (DbUser u in userLsit)
                    {
                        if (u.isAdmin == 1)
                        {
                            dic.Add("isAdmin", userLsit[0].isAdmin.ToString());
                            break;
                        }
                        else
                        {
                            //if(u.baseCode.Equals(json["baseCode"].ToString())){
                            dic.Add("isAdmin", userLsit[0].isAdmin.ToString());
                            break;
                            //}
                        }
                    }

                }
                sb.Clear();
                sb.Append(" select menuCode,operates from sys_powerConfig_users ");
                sb.Append(" where 1=1 ");
                if (!string.IsNullOrWhiteSpace(json["userCode"].ToString()))
                {
                    sb.Append(" and userCode='" + json["userCode"].ToString() + "'");
                }
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count > 0)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        var tempList = new List<string>();
                        var operate = row["operates"].ToString();
                        if (operate.IndexOf(',') != -1)
                        {
                            var arr = operate.Split(',');
                            foreach (String s in arr)
                            {
                                tempList.Add(s);
                            }
                        }
                        else
                        {
                            tempList.Add(operate);
                        }
                        dic.Add(row["menuCode"].ToString(), tempList);
                    }
                }
                rsl.Result = true;
                rsl.Data = dic;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }

        /// <summary>
        /// 获取存货质检项信息的列表
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>getUserPowerList
        public ReturnResult getProductCheckList(string jsonStr)
        {
            try
            {
                rsl = new ReturnResult();
                scan = new DbTempScanData();
                oper = new OperateModel();
                StringBuilder sb = new StringBuilder();
                DbProductCheckMain checkMain = new DbProductCheckMain();
                List<SqlParameter> sqlList = new List<SqlParameter>();
                Dictionary<string, object> checkInfo = new Dictionary<string, object>();
                List<Dictionary<string, object>> checkInfoList = new List<Dictionary<string, object>>();
                #region 获取出入库扫描单号的所有数据
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "参数不能为空";
                    rsl.Result = false;
                    return rsl;
                }
                List<ViewCheckRelation> checkTypeList = new List<ViewCheckRelation>();
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                barInfor = new DbProductBar();
                ViewCheckRelation viewCheck = new ViewCheckRelation();
                if (!string.IsNullOrWhiteSpace(json["barCode"].ToString()))
                {
                    #region 先判断检测主表中是否有数据
                    sb.Clear();
                    sb.Append(" select top 1 * from pr_ProductCheck_main ");
                    sb.Append(" where barCode='" + json["barCode"].ToString() + "'");
                    sb.Append(" order by createtime desc");
                    var checkMainDt = cmd.GetDataTable(sb.ToString());
                    if (checkMainDt.Rows.Count > 0)
                    {
                        var checkResult = checkMainDt.Rows[0]["result"].ToString();
                        var cCode = checkMainDt.Rows[0]["cCode"].ToString();
                        if (!string.IsNullOrWhiteSpace(cCode))
                        {
                            sb.Clear();
                            sb.Append(" select * from pr_ProductCheck_records");
                            sb.Append(" where cCode='" + cCode + "'");
                            var checkRecords = cmd.GetDataTable(sb.ToString());
                            if (checkRecords.Rows.Count > 0)
                            {
                                foreach (DataRow item in checkRecords.Rows)
                                {
                                    checkInfo = new Dictionary<string, object>();
                                    viewCheck.checkCode = item["checkCode"].ToString();
                                    viewCheck.isdel = "0";
                                    var checkList = cmd.GetDataByObject<ViewCheckRelation>(viewCheck);//获取大类检测项
                                    checkInfo.Add("checkResult", checkResult);
                                    checkInfo.Add("checkCode", checkList[0].checkCode.ToString());
                                    checkInfo.Add("checkContent", checkList[0].checkContent.ToString());
                                    checkInfo.Add("result", item["result"]);
                                    checkInfo.Add("memo", item["memo"].ToString());
                                    checkInfoList.Add(checkInfo);
                                }
                                if (checkInfoList.Count > 0)
                                {
                                    rsl.Result = true;
                                    rsl.Data = checkInfoList;
                                    return rsl;
                                }
                            }
                        }
                    }
                    #endregion
                    #region 获取存货的质检信息
                    barInfor.barCode = json["barCode"].ToString();
                    var barList = cmd.GetDataByObject<DbProductBar>(barInfor);
                    if (barList.Count > 0)
                    {
                        viewCheck.proCode = barList[0].proCode;
                        viewCheck.isdel = "0";
                    }
                    else
                    {
                        rsl.Message = "没有数据";
                        rsl.Data = false;
                        return rsl;
                    }
                    var checkProList = cmd.GetDataByObject<ViewCheckRelation>(viewCheck);//获取存货检测项
                    if (checkProList.Count > 0)
                    {
                        foreach (ViewCheckRelation item in checkProList)
                        {
                            checkInfo = new Dictionary<string, object>();
                            checkInfo.Add("checkResult", "pass");//如果没有数据的默认是通过
                            checkInfo.Add("checkCode", item.checkCode.ToString());
                            checkInfo.Add("checkContent", item.checkContent.ToString());
                            checkInfo.Add("result", true);//默认合格
                            checkInfo.Add("memo", "");
                            checkInfoList.Add(checkInfo);
                        }
                        rsl.Data = checkInfoList;
                        rsl.Result = true;
                        return rsl;
                    }
                    #endregion
                    #region 获取存货大类的质检信息
                    sb.Clear();
                    sb.Append(" select typeCode from fun_Inventory_Info where isDel='0' and baseCode='" + json["baseCode"].ToString() + "'");
                    sb.Append(" and proCode='" + barList[0].proCode + "'");
                    var invDt = cmd.GetDataTable(sb.ToString());
                    if (invDt.Rows.Count <= 0)
                    {
                        rsl.Message = "没有存货数据";
                        rsl.Data = false;
                        return rsl;
                    }
                    else
                    {
                        viewCheck = new ViewCheckRelation();
                        viewCheck.proCode = invDt.Rows[0]["typeCode"].ToString();
                        viewCheck.isdel = "0";

                        checkTypeList = cmd.GetDataByObject<ViewCheckRelation>(viewCheck);//获取大类检测项

                        if (checkTypeList.Count > 0)
                        {
                            foreach (ViewCheckRelation item in checkTypeList)
                            {
                                checkInfo = new Dictionary<string, object>();
                                checkInfo.Add("checkResult", "pass");//如果没有数据的默认是通过
                                checkInfo.Add("checkCode", item.checkCode.ToString());
                                checkInfo.Add("checkContent", item.checkContent.ToString());
                                checkInfo.Add("result", true);//默认合格
                                checkInfo.Add("memo", "");
                                checkInfoList.Add(checkInfo);
                            }
                            rsl.Data = checkInfoList;
                            rsl.Result = true;
                            return rsl;
                        }
                        else
                        {
                            rsl.Message = "没有检测数据";
                            rsl.Result = false;
                        }
                    }
                    #endregion
                }
                else
                {
                    rsl.Message = "没有条码数据";
                    rsl.Data = false;
                    return rsl;
                }
                #endregion
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }
        /// <summary>
        /// 获取质检的检测类型
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getCheckTypeList(string jsonStr)
        {
            try
            {
                rsl = new ReturnResult();
                scan = new DbTempScanData();
                oper = new OperateModel();
                StringBuilder sb = new StringBuilder();
                Dictionary<string, string> dic = new Dictionary<string, string>();
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                List<List<Dictionary<string, string>>> debugList = new List<List<Dictionary<string, string>>>();
                DbProductCheckMain checkMain = new DbProductCheckMain();
                List<SqlParameter> sqlList = new List<SqlParameter>();
                #region 获取出入库扫描单号的所有数据
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "参数不能为空";
                    rsl.Result = false;
                    return rsl;
                }
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Clear();
                sb.Append(" select code,name from sys_dictionaries_info");
                if (json["operateType"].ToString().Equals("01"))//入库
                {
                    sb.Append(" where extendFile='pit' and status='1'");
                }
                if (json["operateType"].ToString().Equals("02"))//出库
                {
                    sb.Append(" where extendFile='pot' and status='1'");
                }
                if (json["operateType"].ToString().Equals("03"))//拆装箱
                {
                    sb.Append(" where extendFile='pput' and status='1'");
                }
                if (json["operateType"].ToString().Equals("04"))//调试
                {
                    sb.Append(" where extendFile='pdt' and status='1'");

                }
                if (json["operateType"].ToString().Equals("05"))//质检
                {
                    sb.Append(" where extendFile='pct' and status='1'");
                }
                if (json["operateType"].ToString().Equals("06"))//绩效
                {
                    sb.Append(" where extendFile='pwt' and status='1'");
                }

                var checkDt = cmd.GetDataTable(sb.ToString());
                if (checkDt.Rows.Count > 0)
                {
                    var checkList = cmd.TableToDictionary(checkDt);
                    rsl.Result = true;
                    rsl.Data = checkList;
                }
                else
                {
                    rsl.Result = false;
                    rsl.Message = "没有添加质检种类";
                    return rsl;
                }
                #endregion
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }
        /// <summary>
        /// 获取系统字典表参数
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getDictionaryInfo(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "请求参数不能为空";
                    return rsl;
                }
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Clear();
                sb.Append("select * from sys_dictionaries_info where 1=1 and status=1 ");
                if (json.Property("code") != null && !string.IsNullOrWhiteSpace(json["code"].ToString()))
                {
                    sb.Append(" and code='" + json["code"].ToString() + "' ");
                }
                if (json.Property("name") != null && !string.IsNullOrWhiteSpace(json["name"].ToString()))
                {
                    sb.Append(" and name='" + json["name"].ToString() + "' ");
                }
                if (json.Property("types") != null && !string.IsNullOrWhiteSpace(json["types"].ToString()))
                {
                    sb.Append(" and types='" + json["types"].ToString() + "' ");
                }
                if (json.Property("extendFile") != null && !string.IsNullOrWhiteSpace(json["extendFile"].ToString()))
                {
                    sb.Append(" and extendFile='" + json["extendFile"].ToString() + "' ");
                }
                var sysDt = cmd.GetDataTable(sb.ToString());
                var list = new List<object>();
                if (sysDt != null && sysDt.Rows.Count > 0)
                {
                    foreach (DataRow item in sysDt.Rows)
                    {
                        var temDic = new Dictionary<string, string>();
                        temDic["value"] = item["code"].ToString();
                        temDic["text"] = item["name"].ToString();
                        list.Add(temDic);
                    }
                }
                rsl.Result = true;
                rsl.Data = list;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 获取系统参数表参数
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getParamentersInfo(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "请求参数不能为空";
                    return rsl;
                }
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Clear();
                sb.Append("select * from sys_parameters_info where 1=1 and enable='open' and isDel<>1  ");
                if (json.Property("code") != null && !string.IsNullOrWhiteSpace(json["code"].ToString()))
                {
                    sb.Append(" and parCode='" + json["code"].ToString() + "' ");
                }
                if (json.Property("name") != null && !string.IsNullOrWhiteSpace(json["name"].ToString()))
                {
                    sb.Append(" and parName='" + json["name"].ToString() + "' ");
                }
                var sysDt = cmd.GetDataTable(sb.ToString());
                rsl.Result = true;
                rsl.Data = cmd.TableToDictionary(sysDt);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 获取移动端功能菜单
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getMenuTypeList(string jsonStr)
        {
            try
            {
                rsl = new ReturnResult();
                scan = new DbTempScanData();
                oper = new OperateModel();
                StringBuilder sb = new StringBuilder();
                var parentTable = new DataTable();
                var childTable = new DataTable();
                Dictionary<string, object> childDic = new Dictionary<string, object>();
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                List<List<Dictionary<string, string>>> debugList = new List<List<Dictionary<string, string>>>();
                Dictionary<string, object> dic = new Dictionary<string, object>();
                DbProductCheckMain checkMain = new DbProductCheckMain();
                List<SqlParameter> sqlList = new List<SqlParameter>();
                #region 获取出入库扫描单号的所有数据
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "参数不能为空";
                    rsl.Result = false;
                    return rsl;
                }
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Clear();
                sb.Append(" select * from sys_MenuInfo ");
                sb.Append(" where  mType='APP' and isdel=0 and status='Y'");
                parentTable = cmd.GetDataTable(sb.ToString());
                if (parentTable.Rows.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有获取菜单数据";
                    return rsl;
                }
                var parentList = cmd.TableToDictionary(parentTable);
                dic.Add("parentList", parentList);
                rsl.Result = true;
                rsl.Data = dic;
                #endregion
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }
        /// <summary>
        /// 获取移动端功能菜单（H5端接口）
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult GetMenuList(string jsonStr)
        {
            try
            {
                rsl = new ReturnResult();
                scan = new DbTempScanData();
                oper = new OperateModel();
                StringBuilder sb = new StringBuilder();
                var parentTable = new DataTable();
                var childTable = new DataTable();
                Dictionary<string, object> childDic = new Dictionary<string, object>();
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                List<List<Dictionary<string, string>>> debugList = new List<List<Dictionary<string, string>>>();
                Dictionary<string, object> dic = new Dictionary<string, object>();
                DbProductCheckMain checkMain = new DbProductCheckMain();
                List<SqlParameter> sqlList = new List<SqlParameter>();
                #region 获取出入库扫描单号的所有数据
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "参数不能为空";
                    rsl.Result = false;
                    return rsl;
                }
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Clear();
                sb.Append(" select *,convert(int,orderNum) orderNumi from sys_MenuInfo ");
                sb.Append(" where  mType='APP' and isdel=0 and status='Y'");
                parentTable = cmd.GetDataTable(sb.ToString());
                if (parentTable.Rows.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有获取菜单数据";
                    return rsl;
                }

                #region 获取用户
                var powerDt = new DataTable();
                var isAdmin = false;
                if (json.Property("userCode") != null && !string.IsNullOrWhiteSpace(json["userCode"].ToString()))
                {
                    sb.Clear();
                    sb.Append("select * from sys_users_info where 1=1 and isDel<>1 ");
                    sb.Append(" and status='Y' and userCode='" + json["userCode"].ToString() + "' ");
                    var dt = cmd.GetDataTable(sb.ToString());
                    if (dt == null || dt.Rows.Count < 1)
                    {
                        rsl.Result = false;
                        rsl.Message = "没有获取登陆人信息";
                        return rsl;
                    }
                    if (dt.Rows[0]["isAdmin"].ToString().Equals("1"))
                    {
                        isAdmin = true;
                    }
                    else
                    {
                        var select = dt.Select("baseCode='" + json["baseCode"].ToString() + "'");
                        if (select == null || select.Length < 1)
                        {
                            rsl.Result = false;
                            rsl.Message = "没有获取登陆人信息";
                            return rsl;
                        }
                        var powerRole = select[0]["powerRole"].ToString();
                        if (!string.IsNullOrWhiteSpace(powerRole))
                        {
                            sb.Clear();
                            sb.Append("select gp.* ");
                            sb.Append(" from sys_powerConfig_groups g ");
                            sb.Append("inner join sys_powerConfig_groupPower gp on g.groupCode = gp.groupCode ");
                            sb.Append(" where 1=1 and g.isDel<>1 and status='Y' ");
                            sb.Append(" and g.groupCode='" + powerRole + "'");
                            powerDt = cmd.GetDataTable(sb.ToString());
                            if (powerDt == null || powerDt.Rows.Count < 1)
                            {
                                rsl.Result = false;
                                rsl.Message = "无权限";
                                return rsl;
                            }
                        }
                        else
                        {
                            rsl.Result = false;
                            rsl.Message = "无权限";
                            return rsl;
                        }
                    }
                }
                else
                {
                    rsl.Result = false;
                    rsl.Message = "没有获取登陆人信息";
                    return rsl;
                }
                #endregion
                var selectParent = parentTable.Select("menuLevel='1'");
                var parentList = new List<Dictionary<string, object>>();
                if (selectParent != null && selectParent.Length > 0)
                {
                    var dt = selectParent.CopyToDataTable<DataRow>();
                    var dv = dt.DefaultView;
                    dv.Sort = "orderNumi asc";
                    dt = dv.ToTable();
                    foreach (DataRow item in dt.Rows)
                    {
                        var obj = new Dictionary<string, object>();
                        obj["title"] = item["menuName"].ToString();
                        obj["code"] = item["menuCode"].ToString();
                        obj["name"] = item["menuName"].ToString();
                        obj["menuCount"] = 4;
                        obj["pathUrl"] = item["menuPath"].ToString();
                        obj["icon"] = item["menuIcon"].ToString();
                        if (!string.IsNullOrWhiteSpace(item["memo"].ToString()))
                        {
                            var memoDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(item["memo"].ToString());
                            obj["color"] = "#ffffff";
                            obj["size"] = "30";
                            obj["imageColor"] = "#ba251e, #ba4805";
                            obj["pageType"] = "01";
                            if (memoDic.ContainsKey("color") && !string.IsNullOrWhiteSpace(memoDic["color"].ToString()))
                            {
                                obj["color"] = memoDic["color"];
                            }
                            if (memoDic.ContainsKey("imageColor") && !string.IsNullOrWhiteSpace(memoDic["imageColor"].ToString()))
                            {
                                obj["imageColor"] = memoDic["imageColor"].ToString();
                            }
                            if (memoDic.ContainsKey("size") && !string.IsNullOrWhiteSpace(memoDic["size"].ToString()))
                            {
                                obj["size"] = memoDic["size"].ToString();
                            }
                            if (memoDic.ContainsKey("pageType") && !string.IsNullOrWhiteSpace(memoDic["pageType"].ToString()))
                            {
                                obj["pageType"] = memoDic["pageType"].ToString();
                            }
                        }
                        var menuList = new List<Dictionary<string, object>>();
                        var selectChildren = parentTable.Select("parentMenu='" + item["menuCode"].ToString() + "'");
                        if (selectChildren != null && selectChildren.Length > 0)
                        {
                            var cdt = selectChildren.CopyToDataTable<DataRow>();
                            var cdv = cdt.DefaultView;
                            cdv.Sort = "orderNumi asc";
                            cdt = cdv.ToTable();
                            foreach (DataRow ci in cdt.Rows)
                            {
                                this.createMenu(parentTable, ci, ref menuList, isAdmin, powerDt);
                            }
                        }
                        obj["list"] = menuList;
                        if (menuList.Count > 0)
                        {
                            parentList.Add(obj);
                        }
                    }
                }
                //var parentList = cmd.TableToDictionary(parentTable);
                dic.Add("parentList", parentList);
                rsl.Result = true;
                rsl.Data = dic;
                #endregion
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }
        /// <summary>
        /// 创建菜单列表
        /// </summary>
        /// <param name="parentTable"></param>
        /// <param name="item"></param>
        /// <param name="menuList"></param>
        /// <param name="isAdmin"></param>
        /// <param name="powerDt"></param>
        private void createMenu(DataTable parentTable, DataRow item, ref List<Dictionary<string, object>> menuList, Boolean isAdmin = false, DataTable powerDt = null)
        {
            var obj = new Dictionary<string, object>();
            obj["title"] = item["menuName"].ToString();
            obj["code"] = item["menuCode"].ToString();
            obj["name"] = item["menuName"].ToString();
            obj["menuCount"] = 4;
            obj["pathUrl"] = item["menuPath"].ToString();
            obj["icon"] = item["menuIcon"].ToString();
            if (!string.IsNullOrWhiteSpace(item["memo"].ToString()))
            {
                var memoDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(item["memo"].ToString());
                obj["color"] = "#ffffff";
                obj["size"] = "30";
                obj["imageColor"] = "#ba251e, #ba4805";
                obj["pageType"] = "01";
                if (memoDic.ContainsKey("color") && !string.IsNullOrWhiteSpace(memoDic["color"].ToString()))
                {
                    obj["color"] = memoDic["color"];
                }
                if (memoDic.ContainsKey("imageColor") && !string.IsNullOrWhiteSpace(memoDic["imageColor"].ToString()))
                {
                    obj["imageColor"] = memoDic["imageColor"].ToString();
                }
                if (memoDic.ContainsKey("size") && !string.IsNullOrWhiteSpace(memoDic["size"].ToString()))
                {
                    obj["size"] = memoDic["size"].ToString();
                }
                if (memoDic.ContainsKey("pageType") && !string.IsNullOrWhiteSpace(memoDic["pageType"].ToString()))
                {
                    obj["pageType"] = memoDic["pageType"].ToString();
                }
            }
            //var menuList = new List<Dictionary<string, object>>();
            var pmenuList = new List<Dictionary<string, object>>();
            //获取子菜单
            var selectChildren = parentTable.Select("parentMenu='" + item["menuCode"].ToString() + "'");
            if (selectChildren != null && selectChildren.Length > 0)
            {
                var cdt = selectChildren.CopyToDataTable<DataRow>();
                var cdv = cdt.DefaultView;
                cdv.Sort = "orderNumi asc";
                cdt = cdv.ToTable();
                foreach (DataRow ci in cdt.Rows)
                {
                    this.createMenu(parentTable, ci, ref pmenuList, isAdmin, powerDt);
                }
            }
            else
            {
                #region 判断是否有该菜单权限
                if (!isAdmin && powerDt != null && powerDt.Rows.Count > 0)
                {
                    var powerSelect = powerDt.Select("menuCode='" + item["menuCode"].ToString() + "'");
                    if (powerSelect != null && powerSelect.Length > 0)
                    {
                        if (string.IsNullOrWhiteSpace(powerSelect[0]["operates"].ToString()))
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                #endregion
            }
            obj["list"] = pmenuList;
            menuList.Add(obj);
        }
        /// <summary>
        /// 获取质检扫描的条码的存货信息
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getCheckProductInfo(string jsonStr)
        {
            try
            {
                rsl = new ReturnResult();
                scan = new DbTempScanData();
                oper = new OperateModel();
                StringBuilder sb = new StringBuilder();
                DbProductCheckMain checkMain = new DbProductCheckMain();
                List<SqlParameter> sqlList = new List<SqlParameter>();
                List<OperateModel> list = new List<OperateModel>();
                #region 获取出入库扫描单号的所有数据
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "参数不能为空";
                    rsl.Result = false;
                    return rsl;
                }
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                barInfor = new DbProductBar();
                ViewCheckRelation viewCheck = new ViewCheckRelation();
                if (!string.IsNullOrWhiteSpace(json["barCode"].ToString()))
                {
                    barInfor.barCode = json["barCode"].ToString();
                    var barList = cmd.GetDataByObject<DbProductBar>(barInfor);
                    if (barList.Count > 0)
                    {
                        foreach (DbProductBar item in barList)
                        {
                            if (item.barStatus.Equals("bar-drop"))
                            {
                                rsl.Result = false;
                                rsl.Message = "扫描条码已废弃";
                                return rsl;
                            }
                            //如果是计入绩效需判定状态
                            //if (json["money"].ToString().Equals("1"))
                            //{
                            //如果条码状态为返工
                            if (item.barStatus.Equals("need-rework"))
                            {
                                barInfor = new DbProductBar();
                                barInfor.barCode = json["barCode"].ToString();
                                barInfor.barStatus = "need-check";
                                oper = new OperateModel();
                                oper.Data = barInfor;
                                oper.Types = OperateModel.OperateType.Edit;
                                oper.Conditions = "barCode";
                                list.Add(oper);
                            }
                            else
                            {
                                //只有生产检测才会判定状态
                                if (json["checkType"].ToString().Equals("pcw") && !item.barStatus.Equals("need-check"))
                                {
                                    rsl.Result = false;
                                    rsl.Message = "扫描条码为" + getBarStatus(item.barStatus) + "不是待检测状态";
                                    return rsl;
                                }
                                if (!json["checkType"].ToString().Equals("pcw") && item.barStatus.Equals("need-check"))
                                {
                                    rsl.Result = false;
                                    rsl.Message = "扫描条码是待检测状态,只能通过生产检测";
                                    return rsl;
                                }
                            }
                            //}
                        }
                        rsl = cmd.MoreUpdate(list);
                        if (!rsl.Result)
                        {
                            return rsl;
                        }
                        rsl.Data = barList;
                        rsl.Result = true;
                    }
                    else
                    {
                        rsl.Message = "没有该条码数据";
                        rsl.Data = false;
                        return rsl;
                    }
                }

                #region 从检测表中查询改条码是否已经扫描
                //checkMain.barCode = json["barCode"].ToString();
                //var checkList = cmd.GetDataByObject<DbProductCheckMain>(checkMain);
                //if (checkList.Count > 0)
                //{
                //    foreach (DbProductCheckMain item in checkList)
                //    {
                //        if(json.Property("isMoney")!=null){
                //            if(string.IsNullOrWhiteSpace(json["isMoney"].ToString())){
                //                if(json["isMoney"].ToString().Equals("1")){
                //        if (item.result.Equals("pass") || item.Equals("concession"))
                //        {
                //            rsl.Message = "该条码已检测为合格";
                //            rsl.Result = false;
                //            return rsl;
                //        }
                //                }
                //            }
                //        }
                //    }  
                //}
                #endregion
                #endregion
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }
        /// <summary>
        /// 保存条码的质检信息
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult addProductCheckInfo(string jsonStr)
        {
            #region 保存条码的质检信息
            rsl = new ReturnResult();
            return rsl;
            #endregion
        }

      
        /// <summary>
        /// 获取出入库扫描单号里的所有条码数据
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getInputList(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                scan = new DbTempScanData();
                oper = new OperateModel();
                StringBuilder sb = new StringBuilder();
                List<SqlParameter> sqlList = new List<SqlParameter>();
                Dictionary<string, string> dic = new Dictionary<string, string>();
                Dictionary<string, object> dicList = new Dictionary<string, object>();
                List<int> widthList = new List<int>();//每列的宽度
                #region 获取出入库扫描单号的所有数据
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "参数不能为空";
                    rsl.Result = false;
                    return rsl;
                }
                //解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                barInfor = new DbProductBar();
                if (!string.IsNullOrWhiteSpace(json["tempCode"].ToString()))
                {
                    scan.tempCode = json["tempCode"].ToString();
                    scan.operateType = json["operateType"].ToString();
                    var scanList = cmd.GetDataByObject<DbTempScanData>(scan);//获取所有的扫描单号
                    if (scanList.Count > 0)
                    {
                        string barCode = string.Empty;
                        for (int i = 0; i < scanList.Count; i++)
                        {
                            if (scanList[i].barCode != null && !string.IsNullOrWhiteSpace(scanList[i].barCode.ToString()))
                            {
                                barCode += "'" + scanList[i].barCode.ToString() + "'" + ",";
                            }
                        }
                        sb.Clear();
                        sb.Append(getBarInfoList(barCode.TrimEnd(','), json["baseCode"].ToString()));

                        var dt = cmd.GetDataTable(sb.ToString());

                        var list = baseCommon.TableToDictionary(dt);

                        dic = new Dictionary<string, string>();
                        #region
                        if (json.Property("inOutType") != null && !string.IsNullOrWhiteSpace(json["inOutType"].ToString()))
                        {
                            var widths = new int[] { 150, 150, 150, 150, 150, 150, 150, 200, 200, 150, 150, 150, 150 };
                            widthList = widths.ToList();
                            dic.Add("barCode", "条码");
                            dic.Add("proCode", "存货编码");
                            dic.Add("proName", "存货名称");
                            dic.Add("proStyle", "规格");
                            dic.Add("number", "净重");
                        }
                        #endregion

                        if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                        {
                            #region 构建列表数据
                            #region 构建列表元素显示格式
                            var headList = new List<object>();
                            var hList = new List<Dictionary<string, string>>();
                            createHead(ref hList, "barCode", "条码号");
                            headList.Add(hList);
                            hList = new List<Dictionary<string, string>>();
                            createHead(ref hList, "proName", "存货名称");
                            headList.Add(hList);
                            hList = new List<Dictionary<string, string>>();
                            createHead(ref hList, "proStyle", "规格");
                            createHead(ref hList, "number", "净重");
                            headList.Add(hList);
                            #endregion

                            #region 数据分页显示
                            //总条数
                            var pageCount = "0";
                            //总页数
                            var pageNumber = "0";
                            //每页条数
                            var pageSize = "20";
                            var paraList = cmd.getParam("appPageSize");
                            if (paraList != null && paraList.Count > 0)
                            {
                                if (!string.IsNullOrWhiteSpace(paraList[0].parValue))
                                {
                                    pageSize = paraList[0].parValue;
                                }
                            }
                            var table = cmd.PageTableList(dt, json["pageIndex"].ToString(), pageSize, ref pageCount, ref pageNumber);
                            table.Columns.Add("barList");
                            var listDt = new DataTable();

                            var temlist = cmd.TableToDictionary(table);
                            var listInfo = new Dictionary<string, object>();
                            listInfo.Add("head", headList);
                            listInfo.Add("list", temlist);

                            listInfo.Add("mxHead", headList);
                            var barMXList = new List<object>();
                            listInfo.Add("mxList", barMXList);

                            #endregion

                            listInfo.Add("pageNumber", pageNumber);
                            var pageIndex = int.Parse(json["pageIndex"].ToString());
                            listInfo.Add("pageIndex", pageIndex.ToString());
                            dicList.Add("listInfo", listInfo);
                            #endregion

                            #region 构建汇总数据
                            headList = new List<object>();
                            hList = new List<Dictionary<string, string>>();
                            createHead(ref hList, "count", "总件数");
                            createHead(ref hList, "number", "总重量");
                            headList.Add(hList);
                            #region 汇总列表中信息
                            var sumDic = new Dictionary<string, string>();
                            var number = 0m;
                            var count = 0;
                            var weight = 0.0m;

                            if (list != null && list.Count > 0)
                            {
                                foreach (var item in list)
                                {
                                    var jWeight = item["number"].ToString();
                                    if (!string.IsNullOrWhiteSpace(jWeight) && Convert.ToDecimal(jWeight) > 0)
                                    {
                                        number += decimal.Parse(jWeight);
                                    }
                                }
                                count = list.Count;
                            }
                            sumDic.Add("count", count.ToString());
                            sumDic.Add("number", number.ToString());
                            var sumDicList = new List<Dictionary<string, string>>();
                            sumDicList.Add(sumDic);
                            #endregion
                            var sumList = new Dictionary<string, object>();
                            sumList.Add("head", headList);
                            sumList.Add("list", sumDicList);
                            dicList.Add("sumList", sumList);
                            #endregion

                        }
                        else
                        {
                            list.Insert(0, dic);
                            dicList.Add("widthList", widthList);
                            dicList.Add("list", list);
                        }


                        rsl.Data = dicList;
                        rsl.Result = true;
                    }
                    else
                    {
                        rsl.Message = "没有数据";
                        rsl.Data = false;
                        return rsl;
                    }
                }
                else
                {
                    rsl.Message = "没有数据";
                    rsl.Data = false;
                    return rsl;
                }
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        /// <summary>
        /// 获取出入库扫描单号的数据信息
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getInputData(string jsonStr)
        {
            rsl = new ReturnResult();
            oper = new OperateModel();
            #region 获取出入库扫描单号的所有数据
            if (string.IsNullOrWhiteSpace(jsonStr))
            {
                rsl.Message = "参数不能为空";
                rsl.Result = false;
                return rsl;
            }
            //解密
            jsonStr = Encryption.DesDecrypt(jsonStr);
            var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
            barInfor = new DbProductBar();
            if (!string.IsNullOrWhiteSpace(json["tempCode"].ToString()))
            {
                scan.tempCode = json["tempCode"].ToString();
                scan.operateType = json["operateType"].ToString();
                var scanList = cmd.GetDataByObject<DbTempScanData>(scan);//获取所有的扫描单号
                if (scanList.Count > 0)
                {
                    rsl.Data = scanList[0];
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = "没有数据";
                    rsl.Data = false;
                    return rsl;
                }

            }

            #endregion
            return rsl;
        }

        /// <summary>
        /// 获取发货单明细对应扫描临时表中各行的汇总
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getTemScanSaleOrderList(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "未获取到请求参数";
                    return rsl;
                }
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                #region 获取发货单数据
                sb.Clear();
                //cDefine1实际客户(客户名称在U8是唯一的)，cDefine2实际业务员
                sb.Clear();
                sb.Append("select inv.cInvName,isnull(sum(convert(decimal(18,0),isnull(mains.iQuantity,0))),0) iQuantity,  ");//填写U8销售订单信息
                sb.Append(" isnull(sum(convert(decimal(18,0),isnull(mains.fOutQuantity,0))),0) fOutQuantity,mains.cInvCode,mains.cFree1,cFree3   ");
                sb.Append(" from DispatchList main ");
                sb.Append(" inner join DispatchLists mains on main.DLID = mains.DLID  ");
                sb.Append(" inner join inventory inv on inv.cInvCode=mains.cInvCode ");
                sb.Append("  where isnull(main.cVerifier,'') <>'' and isnull(main.dverifydate,'') <>''  ");
                sb.Append("  and main.cDLCode='" + json["outOrderCode"].ToString() + "' ");
                sb.Append(" group by inv.cInvName,mains.cInvCode,mains.cFree1,cFree3 ");
                var orderDt = cuHelper.getData(sb.ToString(), json["baseCode"].ToString());

                #endregion 获取发货单数据
                #region 获取扫描临时表中条码数据
                sb.Clear();
                sb.Append("select bars.proCode,bars.color,bars.trademark,sum(isnull(bars.number,0)) number  ");
                sb.Append(",count(bars.barCode) barC ");
                sb.Append(" from bar_TempScanData_info tem ");
                sb.Append(" inner join bar_ProductBarCode_Sub_info bars on bars.barCode=tem.barCode ");
                sb.Append(" where 1=1 and tem.tempCode='" + json["tempCode"].ToString() + "' ");
                sb.Append(" group by bars.proCode,bars.color,bars.trademark ");
                var barDt = cmd.GetDataTable(sb.ToString());
                #endregion 获取扫描临时表中条码数据

                #region 统计各个存货中扫描的条数
                if (orderDt != null && orderDt.Rows.Count > 0)
                {
                    orderDt.Columns.Add("scanNum");//添加扫描列
                    orderDt.Columns.Add("scanCou");//添加扫描列
                    for (int i = 0; i < orderDt.Rows.Count; i++)
                    {
                        var row = orderDt.Rows[i];
                        var number = 0;
                        var count = 0;
                        if (barDt != null && barDt.Rows.Count > 0)
                        {
                            var selectStr = "proCode='" + row["cInvCode"] + "' and color='" + row["cFree1"]
                            + "' and trademark='" + row["cFree3"].ToString() + "'";
                            var barLength = barDt.Select(selectStr);
                            if (barLength != null && barLength.Length > 0)
                            {
                                foreach (DataRow item in barLength)
                                {
                                    number += int.Parse(item["number"].ToString());
                                    count += int.Parse(item["barC"].ToString());
                                }

                            }
                        }
                        row["scanNum"] = number;
                        row["scanCou"] = count;
                    }
                }
                #endregion 统计各个存货中扫描的条数

                #region 构建表头数据
                var headData = new List<object>();
                var head = new Dictionary<string, string>();
                var obj = new { field = "cInvCode", name = "存货编码", width = "90" };
                headData.Add(obj);
                obj = new { field = "cInvName", name = "存货名称", width = "130" };
                headData.Add(obj);
                obj = new { field = "cFree1", name = "颜色", width = "90" };
                headData.Add(obj);
                obj = new { field = "cFree3", name = "商标", width = "90" };
                headData.Add(obj);
                obj = new { field = "iQuantity", name = "发货数量", width = "70" };
                headData.Add(obj);
                obj = new { field = "fOutQuantity", name = "累计发货数", width = "70" };
                headData.Add(obj);
                obj = new { field = "scanNum", name = "扫描数量", width = "60" };
                headData.Add(obj);
                //obj = new { field = "scanCou", name = "扫描件数", width = "60" };
                //headData.Add(obj);
                #endregion
                var dic = new Dictionary<string, object>();
                dic.Add("headData", headData);
                dic.Add("list", cmd.TableToDictionary(orderDt));
                rsl.Result = true;
                rsl.Data = dic;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }


        public ReturnResult updateApp(string jsonStr)
        {
            rsl = new ReturnResult();
            List<OperateModel> operList = new List<OperateModel>();
            try
            {

                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "传入的参数不能为空";
                    rsl.Result = false;
                    return rsl;
                }
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                txtLog.AddLogMsg("updateApp()方法：" + jsonStr);
                appInfo = new AppMobilesInfo();
                if (!string.IsNullOrWhiteSpace(json["appCode"].ToString()))
                {
                    appInfo.appCode = json["appCode"].ToString();
                }
                var appInfoList = cmd.GetDataByObject<AppMobilesInfo>(appInfo);
                if (appInfoList.Count > 0)
                {
                    if (!string.IsNullOrWhiteSpace(json["versionCode"].ToString()))
                    {
                        appInfo.versionCode = json["versionCode"].ToString();
                    }
                    if (!string.IsNullOrWhiteSpace(json["appVersion"].ToString()))
                    {
                        appInfo.appVersion = json["appVersion"].ToString();
                    }
                    appInfoList = cmd.GetDataByObject<AppMobilesInfo>(appInfo);
                    if (appInfoList.Count > 0)
                    {
                        sb = new StringBuilder();
                        sb.Append(" select top 1 * from [dbo].[app_updateInfo] ");
                        sb.Append(" where versionCode > '" + json["versionCode"].ToString() + "'  ");
                        sb.Append(" order by versionCode");
                        var updateDt = cmd.GetDataTable(sb.ToString());
                        if (updateDt.Rows.Count > 0)
                        {
                            rsl.Data = cmd.TableToDictionary(updateDt);
                            rsl.Result = true;
                            return rsl;
                        }
                        else
                        {
                            rsl.Message = "无更新内容";
                            rsl.Result = false;
                            return rsl;
                        }
                    }
                    else
                    {

                        #region 添加移动端本机信息
                        appInfo.createtime = getNow();
                        oper = new OperateModel();
                        oper.Data = appInfo;
                        oper.Types = OperateModel.OperateType.Edit;
                        oper.Conditions = "appCode";
                        operList.Add(oper);
                        #endregion
                        #region 添加更新信息
                        //appUpdateInfo = new AppUpdateInfo();
                        //appUpdateInfo.appCode = json["appCode"].ToString();
                        //var appUpdateList = cmd.GetDataByObject<AppUpdateInfo>(appUpdateInfo);
                        //if(appUpdateList.Count<=0){
                        //    appUpdateInfo = new AppUpdateInfo();
                        //    appUpdateInfo.appCode = json["appCode"].ToString();
                        //    oper = new OperateModel();
                        //    oper.Data = appUpdateInfo;
                        //    oper.Types = OperateModel.OperateType.Add;
                        //    operList.Add(oper);
                        //}
                        #endregion
                    }
                }
                else
                {
                    #region 添加移动端本机信息
                    if (!string.IsNullOrWhiteSpace(json["versionCode"].ToString()))
                    {
                        appInfo.versionCode = json["versionCode"].ToString();
                    }
                    if (!string.IsNullOrWhiteSpace(json["appVersion"].ToString()))
                    {
                        appInfo.appVersion = json["appVersion"].ToString();
                    }
                    appInfo.createuser = json["createuser"].ToString();
                    appInfo.createtime = getNow();
                    appInfo.status = "1";
                    oper = new OperateModel();
                    oper.Data = appInfo;
                    oper.Types = OperateModel.OperateType.Add;
                    operList.Add(oper);
                    #endregion
                }
                rsl = cmd.MoreUpdate(operList);
                if (!rsl.Result)
                {
                    rsl.Message = "本机信息添加失败";
                    rsl.Result = false;
                    return rsl;
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 获取H5移动端版本号并检测是否需要更新系统
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult updateEditionApp(string jsonStr)
        {
            rsl = new ReturnResult();
            List<OperateModel> operList = new List<OperateModel>();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "传入的参数不能为空";
                    rsl.Result = false;
                    return rsl;
                }
                //jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                txtLog.AddLogMsg("updateApp()方法：" + jsonStr);
                appInfo = new AppMobilesInfo();
                if (!string.IsNullOrWhiteSpace(json["appCode"].ToString()))
                {
                    appInfo.appCode = json["appCode"].ToString();
                }
                var appInfoList = cmd.GetDataByObject<AppMobilesInfo>(appInfo);
                if (appInfoList.Count > 0)
                {
                    if (!string.IsNullOrWhiteSpace(json["versionCode"].ToString()))
                    {
                        appInfo.versionCode = json["versionCode"].ToString();
                    }
                    if (!string.IsNullOrWhiteSpace(json["appVersion"].ToString()))
                    {
                        appInfo.appVersion = json["appVersion"].ToString();
                    }
                    appInfoList = cmd.GetDataByObject<AppMobilesInfo>(appInfo);
                    txtLog.AddLogMsg("update" + JsonConvert.SerializeObject(appInfo) + "ds:" + appInfoList.Count);
                    if (appInfoList.Count > 0)
                    {
                        sb = new StringBuilder();
                        sb.Append(" select top 1 * from [dbo].[app_updateInfo] ");
                        sb.Append(" where convert(int,versionCode) > " + json["versionCode"].ToString() + "  ");
                        sb.Append(" order by versionCode");
                        txtLog.AddLogMsg("updatesb.ToString()" + sb.ToString());
                        var updateDt = cmd.GetDataTable(sb.ToString());
                        if (updateDt.Rows.Count > 0)
                        {
                            txtLog.AddLogMsg("update" + JsonConvert.SerializeObject(cmd.TableToDictionary(updateDt)));
                            var row = updateDt.Rows[0];
                            var data = new Dictionary<string, object>();
                            // 版本更新内容 支持<br>自动换行
                            data["describe"] = row["versionDesc"].ToString();
                            //apk、wgt包下载地址或者应用市场地址
                            //安卓应用市场 market://details?id=xxxx
                            //苹果store itms-apps://itunes.apple.com/cn/app/xxxxxx
                            data["edition_url"] = row["downloadUrl"].ToString();
                            //是否强制更新 0代表否 1代表是
                            data["edition_force"] = row["isForced"].ToString();
                            //0是整包升级（apk或者appstore或者安卓应用市场） 1是wgt升级
                            data["package_type"] = row["isWgtPackage"].ToString();
                            //是否发行  0否 1是 为了控制上架应用市场审核时不能弹出热更新框
                            data["edition_issue"] = 1;
                            //版本号 最重要的manifest里的版本号
                            data["edition_number"] = row["versionCode"].ToString();
                            // 版本名称 manifest里的版本名称
                            data["edition_name"] = row["versionName"].ToString();
                            // 是否静默更新 0代表否 1代表是
                            data["edition_silence"] = 0;
                            rsl.Data = data;
                            rsl.Result = true;
                            return rsl;
                        }
                        else
                        {
                            rsl.Message = "无更新内容";
                            rsl.Result = true;
                            return rsl;
                        }
                    }
                    else
                    {
                        #region 添加移动端本机信息
                        appInfo.mobilesType = json["version_type"].ToString();
                        appInfo.mVendor = json["mVendor"].ToString();
                        appInfo.mModel = json["mModel"].ToString();
                        appInfo.createtime = getNow();
                        oper = new OperateModel();
                        oper.Data = appInfo;
                        oper.Types = OperateModel.OperateType.Edit;
                        oper.Conditions = "appCode";
                        operList.Add(oper);
                        #endregion
                    }
                }
                else
                {
                    #region 添加移动端本机信息
                    if (!string.IsNullOrWhiteSpace(json["versionCode"].ToString()))
                    {
                        appInfo.versionCode = json["versionCode"].ToString();
                    }
                    if (!string.IsNullOrWhiteSpace(json["appVersion"].ToString()))
                    {
                        appInfo.appVersion = json["appVersion"].ToString();
                    }
                    appInfo.mobilesType = json["version_type"].ToString();
                    appInfo.mVendor = json["mVendor"].ToString();
                    appInfo.mModel = json["mModel"].ToString();
                    appInfo.createuser = "admin";
                    appInfo.createtime = getNow();
                    appInfo.status = "1";
                    oper = new OperateModel();
                    oper.Data = appInfo;
                    oper.Types = OperateModel.OperateType.Add;
                    operList.Add(oper);
                    #endregion
                }
                rsl = cmd.MoreUpdate(operList);
                if (!rsl.Result)
                {
                    rsl.Message = "本机信息添加失败";
                    rsl.Result = false;
                    return rsl;
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        ///获取条码的状态信息
        /// </summary>
        /// <param name="barStatus"></param>
        /// <returns></returns>
        public string getBarStatus(string barStatus)
        {

            sb = new StringBuilder();
            var status = "";
            sb.Append(" select name from sys_dictionaries_info where status=1 ");
            if (!string.IsNullOrWhiteSpace(barStatus))
            {
                sb.Append(" and code='" + barStatus + "'");
            }
            var dt = cmd.GetDataTable(sb.ToString());
            if (dt.Rows.Count > 0)
            {
                status = dt.Rows[0]["name"].ToString();
            }
            return status;
        }
   

        /// <summary>
        /// 获取列表条码信息
        /// </summary>
        /// <param name="barCodes"></param>
        /// <param name="baseCode"></param>
        /// <returns></returns>
        private string getBarInfoList(string barCodes, string baseCode)
        {
            sb = new StringBuilder();
            if (!string.IsNullOrWhiteSpace(barCodes) && !string.IsNullOrWhiteSpace(baseCode))
            {
                sb.Append("select bar.barCode,inv.proCode,inv.proName,inv.spec as proStyle,");
                sb.Append("bar.proWeight as number, bar.barStatus from bar_ProductBarCode_info bar ");
                sb.Append("left join fun_Inventory_Info inv on bar.proCode = inv.proCode  ");
                sb.Append(" and inv.isDel=0 and inv.baseCode='" + baseCode + "' ");
                sb.Append(" where bar.barCode in(" + barCodes + ")");
            }
            return sb.ToString();
        }
        /// <summary>
        /// 判断扫描的存货是否与箱码中的存货相同
        /// </summary>
        /// <param name="barCode">箱码中已存在的条码</param>
        /// <param name="scanBarCode">现扫描的条码</param>
        /// <returns></returns>
        private ReturnResult checkBarPro(List<DbProductBar> list, string scanBarCode)
        {
            if (list.Count > 0)
            {
                foreach (DbProductBar item in list)
                {
                    if (!item.proCode.ToString().Equals(scanBarCode))
                    {
                        rsl.Message = "禁止装入多品种货物";
                        rsl.Result = false;
                    }
                    else
                    {
                        rsl.Result = true;
                    }
                }
            }
            return rsl;
        }
        /// <summary>
        /// 判断扫描的存货状态是否与箱码中的存货状态相同
        /// </summary>
        /// <param name="barCode">箱码中已存在的条码</param>
        /// <param name="scanBarCode">现扫描的条码</param>
        /// <returns></returns>
        private ReturnResult checkBarStatus(List<DbProductBar> list, string scanBarCode)
        {
            if (list.Count > 0)
            {
                foreach (DbProductBar item in list)
                {
                    if (!item.barStatus.ToString().Equals(scanBarCode))
                    {
                        rsl.Message = "禁止装入不同出入库状态的货物";
                        rsl.Result = false;
                    }
                    else
                    {
                        rsl.Result = true;
                    }
                }
            }
            return rsl;
        }
     

        /// <summary>
        /// 获取盘点任务信息列表（H5端）
        /// </summary>
        public ReturnResult getCheckTaskList(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                var dicList = new Dictionary<string, object>();
                #region 获取盘点任务
                var tableName = "";
                sb.Clear();
                sb.Append("select *,  ");
                sb.Append("(isnull(proCode,'')+'/'+isnull(proName,'')+'/'+isnull(spec,'')) as proNsp,  ");
                sb.Append("(isnull(color,'')+'/'+isnull(shangbiao,'')) colorBiao ");
                sb.Append(" from V_pch_ProCheckTask_info where 1=1 ");
                sb.Append(" and convert(int,isdel)<>1 and baseCode='" + json["baseCode"].ToString() + "'");
                tableName = sb.ToString();
                sb.Clear();
                sb.Append(" 1=1 ");
                //仓库编码
                if (json.Property("wareHouse") != null && !string.IsNullOrWhiteSpace(json["wareHouse"].ToString()))
                {
                    sb.Append(" and erpWareCode ='" + json["wareHouse"].ToString() + "' ");
                }
                //货位编码
                if (json.Property("goodsPosition") != null && !string.IsNullOrWhiteSpace(json["goodsPosition"].ToString()))
                {
                    sb.Append(" and erpPositionCode ='" + json["goodsPosition"].ToString() + "' ");
                }
                //盘点单号
                if (json.Property("pdCode") != null && !string.IsNullOrWhiteSpace(json["pdCode"].ToString()))
                {
                    sb.Append(" and venCode like '%" + json["pdCode"].ToString() + "%' ");
                }
                //关联单号
                if (json.Property("erpCode") != null && !string.IsNullOrWhiteSpace(json["erpCode"].ToString()))
                {
                    sb.Append(" and erpCode like '%" + json["erpCode"].ToString() + "%' ");
                }
                //存货名称
                if (json.Property("proName") != null && !string.IsNullOrWhiteSpace(json["proName"].ToString()))
                {
                    sb.Append(" and proName  like '%" + json["proName"].ToString() + "%' ");
                }
                //报工时间
                if (json.Property("date") != null && json["date"] != null)
                {
                    var date = JsonConvert.DeserializeObject<string[]>(JsonConvert.SerializeObject(json["date"]));
                    if (date != null && date.Length > 1)
                    {
                        var sDate = date[0].ToString();
                        var eDate = date[1].ToString();
                        sb.Append(" and convert(date,createtime) >= '" + sDate + "'");
                        sb.Append(" and convert(date,createtime) <= '" + eDate + "'");
                    }
                }
                var sqlWhere = sb.ToString();
                var orderStr = " createtime desc ";
                //var dt = cmd.GetDataTable(sb.ToString());
                #region 构建列表数据
                #region 构建列表元素显示格式
                var headList = new List<object>();
                var hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "venCode", "盘点单号");
                createHead(ref hList, "erpCode", "关联单据");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "createtime", "创建时间");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "proNsp", "存货", "#000", "20");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "colorBiao", "类型");
                createHead(ref hList, "chTypeName", "盘点类型");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "wareName", "盘点仓库");
                createHead(ref hList, "positionName", "盘点货位");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "statusName", "任务状态");
                createHead(ref hList, "createuserName", "创建人");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "erpNumber", "用友账面数");
                createHead(ref hList, "scanNumber", "已盘数量");
                headList.Add(hList);
                #endregion

                #region 数据分页显示
                //总条数
                var pageCount = "0";
                //总页数
                var pageNumber = "0";
                //每页条数
                var pageSize = "20";
                var paraList = cmd.getParam("appPageSize");
                if (paraList != null && paraList.Count > 0)
                {
                    if (!string.IsNullOrWhiteSpace(paraList[0].parValue))
                    {
                        pageSize = paraList[0].parValue;
                    }
                }
                #region 自动定位列表信息位置功能
                var table = new DataTable();
                var pageIndex = int.Parse(json["pageIndex"].ToString());
                if (json.Property("selectIndex") != null && !string.IsNullOrWhiteSpace(json["selectIndex"].ToString()) && int.Parse(json["selectIndex"].ToString()) > 0)
                {
                    var page = int.Parse(json["selectIndex"].ToString()) / int.Parse(pageSize);
                    var syCount = int.Parse(json["selectIndex"].ToString()) % int.Parse(pageSize);
                    if (syCount > 0)
                    {
                        page += 1;
                    }
                    var allCount = page * int.Parse(pageSize);//页数的总条数
                    //如果但前索引与到当前页所有数据的总条数相差5就再多请求一页数据；
                    if ((allCount - int.Parse(json["selectIndex"].ToString())) < 5)
                    {
                        page += 1;
                    }
                    //一次性请求的数据
                    var tempageNumber = "0";
                    var tempageCount = "0";
                    var tempageSize = (page * int.Parse(pageSize)).ToString();
                    ////获取正常分页的总页数
                    //table = cmd.PageTableList(dt, "1", pageSize, ref pageCount, ref pageNumber);
                    ////获取一次性到达定位页的所有数据
                    //table = cmd.PageTableList(dt, "1", tempageSize, ref tempageCount, ref tempageNumber);
                    //获取正常分页的总页数
                    table = cmd.PageTableList(tableName, "1", pageSize, sqlWhere, orderStr, ref pageCount, ref pageNumber);
                    //获取一次性到达定位页的所有数据
                    table = cmd.PageTableList(tableName, "1", tempageSize, sqlWhere, orderStr, ref tempageCount, ref tempageNumber);
                    pageIndex = page;//当前页为定位到的页码
                }
                else
                {
                    //table = cmd.PageTableList(dt, json["pageIndex"].ToString(), pageSize, ref pageCount, ref pageNumber);
                    table = cmd.PageTableList(tableName, json["pageIndex"].ToString(), pageSize, sqlWhere, orderStr, ref pageCount, ref pageNumber);
                }
                #endregion
                table.Columns.Add("scanNumber");
                #region 获取盘点任务的已盘条码数量
                if (table != null && table.Rows.Count > 0)
                {
                    var pchCodes = "";
                    foreach (DataRow item in table.Rows)
                    {
                        item["scanNumber"] = "0";
                        pchCodes += "'" + item["pchCode"].ToString() + "'" + ",";
                    }
                    if (!string.IsNullOrWhiteSpace(pchCodes.TrimEnd(',')))
                    {
                        sb.Clear();
                        sb.Append("select * from pCh_CheckTask_records where 1=1 ");
                        sb.Append(" and pchCode in(" + pchCodes.TrimEnd(',') + ") ");
                        var barDt = cmd.GetDataTable(sb.ToString());
                        if (barDt != null && barDt.Rows.Count > 0)
                        {
                            foreach (DataRow item in table.Rows)
                            {
                                var selectRow = barDt.Select("pchCode='" + item["pchCode"].ToString() + "'");
                                if (selectRow != null && selectRow.Length > 0)
                                {
                                    item["scanNumber"] = selectRow.Length.ToString();
                                }
                            }
                        }
                    }
                }
                #endregion
                var temlist = cmd.TableToDictionary(table);
                #endregion
                var listInfo = new Dictionary<string, object>();
                listInfo.Add("head", headList);
                listInfo.Add("list", temlist);
                listInfo.Add("pageNumber", pageNumber);
                listInfo.Add("pageIndex", pageIndex.ToString());
                dicList.Add("listInfo", listInfo);
                #endregion
                #endregion
                rsl.Data = dicList;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }
        /// <summary>
        /// 获取盘点报告信息列表（H5端）
        /// </summary>
        public ReturnResult getCheckTaskReportList(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                var dicList = new Dictionary<string, object>();
                #region 获取盘点报告
                var tableName = "";
                sb.Clear();
                sb.Append("select *, ");
                sb.Append("(isnull(proCode,'')+'/'+isnull(proName,'')+'/'+isnull(spec,'')) as proNsp,  ");
                sb.Append("(isnull(color,'')+'/'+isnull(shangbiao,'')) colorBiao ");
                sb.Append(" from V_pch_proCheckTask_report where 1=1  ");
                sb.Append("   and baseCode='" + json["baseCode"].ToString() + "'");
                tableName = sb.ToString();
                sb.Clear();
                sb.Append(" 1=1 ");
                //仓库编码
                if (json.Property("wareHouse") != null && !string.IsNullOrWhiteSpace(json["wareHouse"].ToString()))
                {
                    sb.Append(" and erpWareCode ='" + json["wareHouse"].ToString() + "' ");
                }
                //货位编码
                if (json.Property("goodsPosition") != null && !string.IsNullOrWhiteSpace(json["goodsPosition"].ToString()))
                {
                    sb.Append(" and erpPositionCode ='" + json["goodsPosition"].ToString() + "' ");
                }
                //盘点单号
                if (json.Property("pdCode") != null && !string.IsNullOrWhiteSpace(json["pdCode"].ToString()))
                {
                    sb.Append(" and erpCode like '%" + json["pdCode"].ToString() + "%' ");
                }
                //存货名称
                if (json.Property("proName") != null && !string.IsNullOrWhiteSpace(json["proName"].ToString()))
                {
                    sb.Append(" and proName  like '%" + json["proName"].ToString() + "%' ");
                }
                //报工时间
                if (json.Property("date") != null && json["date"] != null)
                {
                    var date = JsonConvert.DeserializeObject<string[]>(JsonConvert.SerializeObject(json["date"]));
                    if (date != null && date.Length > 1)
                    {
                        var sDate = date[0].ToString();
                        var eDate = date[1].ToString();
                        sb.Append(" and convert(date,createtime) >= '" + sDate + "'");
                        sb.Append(" and convert(date,createtime) <= '" + eDate + "'");
                    }
                }
                var sqlWhere = sb.ToString();

                var orderStr = " createtime desc ";
                //var dt = cmd.GetDataTable(sb.ToString());
                #region 构建列表数据
                #region 构建列表元素显示格式
                var headList = new List<object>();
                var hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "erpCode", "盘点单号");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "createtime", "创建时间");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "proNsp", "存货", "#000", "20");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "colorBiao", "类型");
                createHead(ref hList, "chTypeName", "盘点类型");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "wareName", "盘点仓库");
                createHead(ref hList, "positionName", "盘点货位");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "createuserName", "创建人");
                createHead(ref hList, "erpNumber", "U8账面数");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "ypNum", "物控账面数");
                createHead(ref hList, "spNum", "实盘数");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "pyNum", "盘盈数");
                createHead(ref hList, "pkNum", "盘亏数");
                headList.Add(hList);
                #endregion

                #region 数据分页显示
                //总条数
                var pageCount = "0";
                //总页数
                var pageNumber = "0";
                //每页条数
                var pageSize = "20";
                var paraList = cmd.getParam("appPageSize");
                if (paraList != null && paraList.Count > 0)
                {
                    if (!string.IsNullOrWhiteSpace(paraList[0].parValue))
                    {
                        pageSize = paraList[0].parValue;
                    }
                }
                #region 自动定位列表信息位置功能
                var table = new DataTable();
                var pageIndex = int.Parse(json["pageIndex"].ToString());
                if (json.Property("selectIndex") != null && !string.IsNullOrWhiteSpace(json["selectIndex"].ToString()) && int.Parse(json["selectIndex"].ToString()) > 0)
                {
                    var page = int.Parse(json["selectIndex"].ToString()) / int.Parse(pageSize);
                    var syCount = int.Parse(json["selectIndex"].ToString()) % int.Parse(pageSize);
                    if (syCount > 0)
                    {
                        page += 1;
                    }
                    var allCount = page * int.Parse(pageSize);//页数的总条数
                    //如果但前索引与到当前页所有数据的总条数相差5就再多请求一页数据；
                    if ((allCount - int.Parse(json["selectIndex"].ToString())) < 5)
                    {
                        page += 1;
                    }
                    //一次性请求的数据
                    var tempageNumber = "0";
                    var tempageCount = "0";
                    var tempageSize = (page * int.Parse(pageSize)).ToString();
                    ////获取正常分页的总页数
                    //table = cmd.PageTableList(dt, "1", pageSize, ref pageCount, ref pageNumber);
                    ////获取一次性到达定位页的所有数据
                    //table = cmd.PageTableList(dt, "1", tempageSize, ref tempageCount, ref tempageNumber);
                    //获取正常分页的总页数
                    table = cmd.PageTableList(tableName, "1", pageSize, sqlWhere, orderStr, ref pageCount, ref pageNumber);
                    //获取一次性到达定位页的所有数据
                    table = cmd.PageTableList(tableName, "1", tempageSize, sqlWhere, orderStr, ref tempageCount, ref tempageNumber);
                    pageIndex = page;//当前页为定位到的页码
                }
                else
                {
                    //table = cmd.PageTableList(dt, json["pageIndex"].ToString(), pageSize, ref pageCount, ref pageNumber);
                    table = cmd.PageTableList(tableName, json["pageIndex"].ToString(), pageSize, sqlWhere, orderStr, ref pageCount, ref pageNumber);
                }
                #endregion

                var temlist = cmd.TableToDictionary(table);
                #endregion
                var listInfo = new Dictionary<string, object>();
                listInfo.Add("head", headList);
                listInfo.Add("list", temlist);
                listInfo.Add("pageNumber", pageNumber);
                listInfo.Add("pageIndex", pageIndex.ToString());
                dicList.Add("listInfo", listInfo);
                #endregion
                #endregion
                rsl.Data = dicList;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }

        /// <summary>
        /// 获取条码追踪信息（H5端）
        /// </summary>
        public ReturnResult getTrackBarCodeInfo(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }

                jsonStr = Encryption.DesDecrypt(jsonStr);
                txtLog.AddLogMsg("条码追踪入参："+jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                var dicList = new List<Dictionary<string, string>>();
                #region 获取条码追踪信息
                sb.Clear();
                sb.Append("select * from V_BarCode_Info  ");
                sb.Append(" where 1=1 ");
                sb.Append(" and barCode='" + json["barCode"].ToString() + "'");
                var barDt = cmd.GetDataTable(sb.ToString());
                if (barDt == null || barDt.Rows.Count < 1)
                {
                    rsl.Message = "没有获取该条码数据";
                    return rsl;
                }

                var row = barDt.Rows[0];
                var itemDic = new Dictionary<string, string>();
                itemDic["title"] = ""; //标题
                itemDic["content"] = ""; //内容
                itemDic["desc"] = "";//时间
                #region 获取条码打印信息
                itemDic = new Dictionary<string, string>();
                itemDic["title"] = "条码打印";
                var content = "";
                var barRow = barDt.Rows[0];
                var bobj = new
                {
                    barCode = "条码号"
                };
                getObjContent(bobj, barRow, ref content);
                content += "\n";
                var cobj = new
                {
                    planCode = "生产计划单",
                    U8relationCode = "关联单据",
                    number = "总数量",
                    proWeight = "重量",
                    cu_customerName = "客户名称",
                    createuserName = "打印人员"
                };
                getObjContent(cobj, barRow, ref content);
                content += "\n";
                #region 获取条码明细数据
                sb.Clear();
                sb.Append("select *,(proCode+'/'+proName+'/'+spec) proNsp  from V_BarCode_Sub_Info  ");
                sb.Append(" where 1=1  ");
                sb.Append(" and barCode='" + json["barCode"].ToString() + "'");
                var barMxDt = cmd.GetDataTable(sb.ToString());
                if (barMxDt != null && barMxDt.Rows.Count > 0)
                {
                    foreach (DataRow r in barMxDt.Rows)
                    {
                        var tobj = new { proNsp = "存货", number = "数量", color = "颜色", trademark = "商标" };
                        getObjContent(tobj, r, ref content);
                        content += "\n";
                    }
                }
                #endregion
                itemDic["content"] = content;
                itemDic["desc"] = barDt.Rows[0]["createtime"].ToString();
                dicList.Add(itemDic);
                #endregion
                #region 获取条码作废信息
                if (row["barStatus"].ToString().Equals("bar-drop"))
                {
                    itemDic = new Dictionary<string, string>();
                    itemDic["title"] = "条码作废";
                    content = "";
                    var memo = row["memo"].ToString();
                    var first = memo.IndexOf('(');
                    var end = memo.IndexOf(')');
                    if (first > -1 && end > -1)
                    {
                        memo = memo.Substring(first + 1, end - first - 1);
                    }
                    var arr = memo.Split(',');
                    if (arr != null && arr.Length > 0)
                    {
                        var userCode = arr[0];
                        var datetime = arr[1];
                        sb.Clear();
                        sb.Append("select * from sys_users_info where 1=1 and status='Y' and isDel<>1 ");
                        sb.Append(" and baseCode='" + json["baseCode"].ToString() + "'");
                        sb.Append(" and userCode='" + userCode + "'");
                        var uDt = cmd.GetDataTable(sb.ToString());
                        if (uDt != null && uDt.Rows.Count > 0)
                        {
                            content += "作废人员：" + uDt.Rows[0]["userName"].ToString();
                        }
                        itemDic["content"] = content;
                        itemDic["desc"] = datetime;
                        dicList.Add(itemDic);
                    }
                }
                #endregion
                #region 获取条码出入库信息
                sb.Clear();
                sb.Append("select m.*,ms.goodsPositionName,ms.targetGoodsPositionName from V_BarEntoryRecords_info m ");
                sb.Append(" left join V_BarEntryRecords_list ms on ms.mCode=m.mCode ");
                sb.Append(" where 1=1 and ms.barCode='" + json["barCode"].ToString() + "'");
                sb.Append(" and m.baseCode='" + json["baseCode"].ToString() + "'");
                sb.Append("order by m.createtime asc ");
                var reDt = cmd.GetDataTable(sb.ToString());
                if (reDt != null && reDt.Rows.Count > 0)
                {
                    foreach (DataRow item in reDt.Rows)
                    {
                        itemDic = new Dictionary<string, string>();
                        var inOutType = item["inOutType"].ToString();
                        itemDic["title"] = item["inOutTypeName"].ToString();
                        content = "";
                        var tobj = new
                        {
                            outOrderCode = "单据号",
                            happenDate = "发生日期",
                            referOrderCode = "参照单据",
                            houseName = "发生仓库",
                            targetWareHouseName = "目标仓库",
                            isBlueName = "单据类型",
                            userName = "创建人",
                            goodsPositionName = "发生货位",
                            targetGoodsPositionName = "目标货位"
                        };
                        var propertys = tobj.GetType().GetProperties();
                        foreach (PropertyInfo proInfo in propertys)
                        {
                            var code = proInfo.Name;
                            var name = proInfo.GetValue(tobj, null);
                            if (code.Equals("referOrderCode"))
                            {
                                if (!string.IsNullOrWhiteSpace(item[code].ToString()))
                                {
                                    content += name + "：" + item[code].ToString() + "   ";
                                }
                            }
                            else
                            {
                                content += name + "：" + item[code].ToString() + "   ";
                            }
                        }
                        itemDic["content"] = content;
                        itemDic["desc"] = item["createtime"].ToString();
                        dicList.Add(itemDic);
                    }
                }
                #endregion
                #endregion
                dicList.Reverse();//元素倒序排列
                rsl.Data = dicList;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }
        /// <summary>
        /// 获取自定义数据格式
        /// </summary>
        /// <param name="bobj"></param>
        /// <param name="row"></param>
        /// <param name="content"></param>
        private void getObjContent(Object bobj, DataRow row, ref string content)
        {
            //var bobj = new { outOrderCode = "单据号", happenDate = "发生日期", referOrderCode = "参照单据", houseName = "仓库名称", isBlueName = "单据类型", userName = "创建人" };
            var propertys = bobj.GetType().GetProperties();
            foreach (PropertyInfo proInfo in propertys)
            {
                var code = proInfo.Name;
                var name = proInfo.GetValue(bobj, null);
                if (!string.IsNullOrWhiteSpace(row[code].ToString()))
                {
                    content += name + "：" + row[code].ToString() + "  ";
                }
            }
        }
    
        /// <summary>
        /// 获取两个时间内的所有时间列表值
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        private List<string> getDateTimeList(string startDate, string endDate)
        {
            var dateList = new List<string>();
            var i = 0;
            while (true)
            {
                var nextDate = Convert.ToDateTime(startDate).AddDays(i);
                dateList.Add(nextDate.ToString("yyyy-MM-dd"));
                if (DateTime.Compare(Convert.ToDateTime(endDate), nextDate) == 0)
                {
                    return dateList;
                }
                i++;
            }
            return dateList;

        }
      

    }
}

